2023-05-13 14:44:17 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2023-05-13 14:44:25 +03:00
|
|
|
|
|
|
|
|
|
2023-05-13 14:44:17 +03:00
|
|
|
// Enum typeclass
|
|
|
|
|
|
|
|
|
|
typeclass Enum =
|
|
|
|
|
& succ : Enum -> (Optional Enum)
|
|
|
|
|
& pred : Enum -> (Optional Enum)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2023-05-13 13:11:12 +03:00
|
|
|
decl ( -- ) : Int -> Int -> Int_0
|
2023-05-13 14:44:17 +03:00
|
|
|
def ( -- ) : begin end = {
|
|
|
|
|
var current = begin
|
|
|
|
|
return (while current < end do {
|
|
|
|
|
; current += 1
|
|
|
|
|
return current - 1
|
|
|
|
|
})
|
|
|
|
|
}
|
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 {
|
|
|
|
|
for i in 0--10 do func: "abacaba"
|
|
|
|
|
}
|