mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
some fixes for zero argument functions, test_code.lang improvements
This commit is contained in:
parent
79bd30c1ee
commit
3188ba6a54
4 changed files with 104 additions and 3 deletions
BIN
tests/.test_code.lang.kate-swp
Normal file
BIN
tests/.test_code.lang.kate-swp
Normal file
Binary file not shown.
|
|
@ -1,5 +1,106 @@
|
|||
decl print : String -> Unit
|
||||
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
|
||||
|
||||
//
|
||||
|
||||
// Enum typeclass
|
||||
|
||||
typeclass Enum =
|
||||
& succ : Enum -> (Optional Enum)
|
||||
& pred : Enum -> (Optional Enum)
|
||||
|
||||
//
|
||||
|
||||
decl ( -- ) : Int -> Int -> Int_0
|
||||
def ( -- ) : begin end = {
|
||||
var current = begin
|
||||
return (while current < end do {
|
||||
; current += 1
|
||||
return current - 1
|
||||
})
|
||||
}
|
||||
|
||||
decl func : String -> Int
|
||||
def func : s = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue