basic Float basic Int basic String basic Char basic Bool basic Unit // bool functions decl not : Bool -> Bool def not : x = match x with | true -> false | false -> true decl ( && ) : Bool -> Bool -> Bool def ( && ) : x y = match x with | true -> ( match y with | true -> true | false -> false ) | false -> false decl ( || ) : Bool -> Bool -> Bool def ( || ) : x y = match x with | true -> true | false -> ( match y with | true -> true | false -> false ) // Eq typeclass typeclass Eq = & ( == ) : Eq -> Bool & ( != ) : Eq -> Bool namespace const Eq { def ( != ) : x = not: (self == x) } // Ord typeclass struct Order = | EQ | LT | GT typeclass (Ord : #Eq) = & compare: Ord -> Order & ( < ) : Ord -> Bool & ( >= ) : Ord -> Bool & ( > ) : Ord -> Bool & ( <= ) : Ord -> Bool & min : Ord -> Ord & max : Ord -> Ord namespace var Ord { def compare : x = if self == x then $EQ elif self < x then $LT else $GT def ( >= ) : x = not: (self < x) def ( > ) : x = x < self def ( <= ) : x = not: (x < self) def min : x = if self < x then self else x def max : x = if self < x then x else self } // typeclass Show = & show : -> String typeclass Read = & read : String -> Read typeclass Debug = & debug : -> String // // Enum typeclass typeclass Enum = & succ : Enum -> (Optional Enum) & pred : Enum -> (Optional Enum) // decl ( -- ) : Int -> Int -> Int_0 def ( -- ) : begin end = { var current = begin return (while current < end do { ; current += 1 return current - 1 }) } decl func : String -> Int def func : s = { ; print: s return 5 } exec main { for i in 0--10 do func: "abacaba" }