2023-05-13 18:53:54 +03:00
|
|
|
// basic Float
|
|
|
|
|
// basic Int
|
|
|
|
|
// basic String
|
|
|
|
|
// basic Char
|
|
|
|
|
// basic Bool
|
|
|
|
|
// basic Unit
|
2023-05-13 14:44:17 +03:00
|
|
|
|
2023-05-13 16:14:02 +03:00
|
|
|
//
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
decl not : Bool -> Bool
|
|
|
|
|
def not : x =
|
2023-05-13 18:53:54 +03:00
|
|
|
(match x with
|
|
|
|
|
| true -> false
|
|
|
|
|
| false -> true)
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
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 =
|
2023-05-13 16:14:02 +03:00
|
|
|
& var ( == ) : Eq -> Bool
|
|
|
|
|
& var ( != ) : Eq -> Bool
|
2023-05-13 14:44:17 +03:00
|
|
|
|
2023-05-13 22:40:33 +03:00
|
|
|
namespace var Eq {
|
2023-05-13 18:53:54 +03:00
|
|
|
def ( != ) : x = not: (self == x)
|
2023-05-13 14:44:17 +03:00
|
|
|
}
|
|
|
|
|
|
2023-05-13 16:14:02 +03:00
|
|
|
//
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
struct Order =
|
|
|
|
|
| EQ
|
|
|
|
|
| LT
|
|
|
|
|
| GT
|
|
|
|
|
|
|
|
|
|
typeclass (Ord : #Eq) =
|
2023-05-13 22:40:33 +03:00
|
|
|
& var compare : Ord -> Order
|
2023-05-13 16:14:02 +03:00
|
|
|
& var ( < ) : Ord -> Bool
|
|
|
|
|
& var ( >= ) : Ord -> Bool
|
|
|
|
|
& var ( > ) : Ord -> Bool
|
|
|
|
|
& var ( <= ) : Ord -> Bool
|
2023-05-13 22:40:33 +03:00
|
|
|
|
|
|
|
|
decl min ('A : #Ord) : 'A -> 'A -> 'A
|
|
|
|
|
def min : x y = if x < y then x else y
|
|
|
|
|
|
|
|
|
|
decl max ('A : #Ord) : 'A -> 'A -> 'A
|
|
|
|
|
def max : x y = if x < y then y else x
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2023-05-20 00:01:54 +03:00
|
|
|
// typeclass Print =
|
|
|
|
|
// & var print : -> String
|
|
|
|
|
//
|
|
|
|
|
// typeclass Read =
|
|
|
|
|
// & var read : String -> Read
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
typeclass Debug =
|
|
|
|
|
& debug : -> String
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2023-05-13 16:14:02 +03:00
|
|
|
typeclass Default =
|
|
|
|
|
& default : -> Default
|
|
|
|
|
|
|
|
|
|
//
|
2023-05-13 14:44:25 +03:00
|
|
|
|
2023-05-13 16:14:02 +03:00
|
|
|
typeclass Bounded =
|
|
|
|
|
& min_bound : -> Bounded
|
|
|
|
|
& max_bound : -> Bounded
|
|
|
|
|
& var is_max_bound : -> Bool
|
|
|
|
|
& var is_min_bound : -> Bool
|
2023-05-13 14:44:25 +03:00
|
|
|
|
2023-05-13 16:14:02 +03:00
|
|
|
//
|
2023-05-13 14:44:17 +03:00
|
|
|
|
|
|
|
|
typeclass Enum =
|
2023-05-13 16:14:02 +03:00
|
|
|
& var succ : -> (Optional Enum)
|
|
|
|
|
& var pred : -> (Optional Enum)
|
2023-05-13 18:53:54 +03:00
|
|
|
& to_enum : Int -> Enum
|
|
|
|
|
& var from_enum : -> Int
|
2023-05-13 16:14:02 +03:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// // bad
|
|
|
|
|
// typeclass Functor 'A =
|
|
|
|
|
// & fmap 'B ('F : (#Functor 'B)) : ('A -> 'B) -> Functor -> 'F
|
|
|
|
|
|
|
|
|
|
// typeclass (Iterator : #Eq) =
|
|
|
|
|
// & next : -> Unit
|
|
|
|
|
// & prev : -> Unit
|
|
|
|
|
//
|
|
|
|
|
// typeclass Iterable ('Iter : #Iterable) =
|
|
|
|
|
// & begin : -> 'Iter
|
|
|
|
|
// & end : -> 'Iter
|
|
|
|
|
|
2023-05-13 14:44:17 +03:00
|
|
|
//
|
|
|
|
|
|
2023-05-13 13:11:12 +03:00
|
|
|
decl ( -- ) : Int -> Int -> Int_0
|
2023-05-17 18:29:39 +03:00
|
|
|
// def ( -- ) : begin end = {
|
|
|
|
|
// var current = begin
|
|
|
|
|
// return (while current < end do {
|
|
|
|
|
// ; current += 1
|
|
|
|
|
// return current - 1
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
decl print : String -> Unit
|
2023-05-20 00:01:54 +03:00
|
|
|
decl read : -> String
|
2023-05-07 19:52:35 +03:00
|
|
|
|
|
|
|
|
decl func : String -> Int
|
|
|
|
|
def func : s = {
|
|
|
|
|
; print: s
|
|
|
|
|
return 5
|
|
|
|
|
}
|
2023-05-13 13:11:12 +03:00
|
|
|
|
|
|
|
|
exec main {
|
2023-05-20 00:01:54 +03:00
|
|
|
for i in (,0 ,1 ,2 ,3) do func: "abacaba"
|
|
|
|
|
; print: ({ return read: })
|
2023-05-13 13:11:12 +03:00
|
|
|
}
|