import std/io trait Describe { fn describe :: x: a -> String } pub type Box { Box(a) } impl Describe { fn describe :: n { "int " <> show n } } impl Describe> where Describe { fn describe :: b { match b { Box(x) -> "box of " <> describe x } } } // Constraints inferred from use become dictionary parameters. fn twice_described :: x { describe x <> " / " <> describe x } pub fn largest :: a: t b: t -> t where Ord { if a > b { a } else { b } } fn sum_all :: xs { match xs { [] -> 0, [x, ..rest] -> x + sum_all rest } } pub fn main :: -> () / { io.println (describe Box(Box(42))) io.println (twice_described Box(7)) io.println ( show (largest 3 9) <> " " <> largest "pear" "apple" <> " " <> show (largest 2.5 (-1.0)) ) io.println (show ([1, 2] == [1, 2]) <> " " <> show (Some(3) == None)) io.println (show (sum_all [1, 2, 3, 4])) } //> box of box of int 42 //> box of int 7 / box of int 7 //> 9 pear 2.5 //> True False //> 10