lang_2023/tests/typeclasses.lang

30 lines
682 B
Text
Raw Normal View History

2023-06-03 19:01:03 +03:00
typeclass \default =
& default : -> \default
2023-03-31 12:10:12 +03:00
2023-06-03 19:01:03 +03:00
typeclass \ord[#eq] =
& var is-less-then : \ord -> \bool
2023-03-31 12:10:12 +03:00
2023-06-03 19:01:03 +03:00
typeclass \d[#a #b #c] 'a 'b =
& var do-something : -> (& 'a & 'b)
2023-03-31 12:10:12 +03:00
2023-06-03 19:01:03 +03:00
typeclass \e 'a =
& var do-something : -> 'a
2023-03-31 12:10:12 +03:00
2023-06-03 19:01:03 +03:00
decl ( == ) 'a[#ord] : 'a -> 'a -> \bool
def ( == ) : a b = a..is-equal-to: b
2023-06-03 19:01:03 +03:00
decl ( != ) 'a[#ord] : 'a -> 'a -> \bool
2023-05-13 14:54:48 +03:00
def ( != ) : a b = not: (a == b)
2023-06-03 19:01:03 +03:00
decl ( < ) 'a[#ord] : 'a -> 'a -> \bool
def ( < ) : a b = a..is-less-then: b
2023-06-03 19:01:03 +03:00
decl ( > ) 'a[#ord] : 'a -> 'a -> \bool
2023-05-11 23:14:36 +03:00
def ( > ) : a b = not: (a <= b)
2023-06-03 19:01:03 +03:00
decl ( <= ) 'a[#ord] : 'a -> 'a -> \bool
2023-05-11 23:14:36 +03:00
def ( <= ) : a b = a < b ||. a == b
2023-06-03 19:01:03 +03:00
decl ( >= ) 'a[#ord] : 'a -> 'a -> \bool
2023-05-11 23:14:36 +03:00
def ( >= ) : a b = not: (a < b)