lang_2023/tests/typeclasses.lang

21 lines
445 B
Text
Raw Normal View History

typeclass Copy =
& copy : Copy -> Copy
2023-03-31 12:10:12 +03:00
typeclass (Ord : #Eq) =
& ( < ) : Ord -> Ord -> Bool
& ( > ) : Ord -> Ord -> Bool
& ( <= ) : Ord -> Ord -> Bool
& ( >= ) : Ord -> Ord -> Bool
2023-03-31 12:10:12 +03:00
typeclass (D : #A #B #C) 'A 'B =
2023-03-31 12:10:12 +03:00
& do_something : Unit -> (& 'A & 'B)
typeclass E 'A =
2023-03-31 12:10:12 +03:00
& do_something : Unit -> 'A
namespace const ord : Ord {
2023-03-31 12:10:12 +03:00
def ( <= ) : a b = (a < b) || (a == b)
def ( > ) : a b = !(a <= b)
def ( >= ) : a b = !(a < b)
}