lang_2023/tests/typeclasses.lang
ProgramSnail 0d62ae0814 debug
2023-03-31 12:10:12 +03:00

36 lines
825 B
Text

typeclass #Copy =
& copy : #Copy -> #Copy
typeclass (#Ord : #Eq) =
& ( < ) : #Ord -> #Ord -> Bool
& ( > ) : #Ord -> #Ord -> Bool
& ( <= ) : #Ord -> #Ord -> Bool
& ( >= ) : #Ord -> #Ord -> Bool
typeclass (#D : #A #B #C) 'A 'B =
& do_something : Unit -> (& 'A & 'B)
typeclass #E 'A =
& do_something : Unit -> 'A
namespace const ord : #Ord {
def ( <= ) : a b = (a < b) || (a == b)
def ( > ) : a b = !(a <= b)
def ( >= ) : a b = !(a < b)
}
// === ?? dependent types ?? ===
//
// typeclass #F : (a : Int) (b : Int) =
// & do_something Int -> Int
//
// namespace (f : #F a b c) {
// require do_sometihng a = b
// }
//
// ===
// ?? operators over functions (without arguments, like "def <= = < || ==;") ??
// ?? define operators like OCaml ??
// ?? denote moved type ??
// ?? "trait" VS "typeclass" ??