mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-07 21:25:31 +00:00
23 lines
464 B
Python
23 lines
464 B
Python
id|T|(x: T): T = x
|
|
assert id(1) == 1
|
|
assert id(True) == True
|
|
assert id("hello") == "hello"
|
|
|
|
const|T, C|(c: C): (T -> C) = (_: T,) -> c
|
|
print! const(1)(2)
|
|
assert const(True)(2) == True
|
|
|
|
print_to_str!|S <: Show|(s: S): Str =
|
|
print! s
|
|
s.__str__()
|
|
|
|
discard print_to_str!(1)
|
|
|
|
add1 x: Int = x + 1
|
|
then|T|(x: T or NoneType, f: (a: T) -> T) =
|
|
match x:
|
|
None -> x
|
|
# y: T
|
|
y -> f y
|
|
assert then(1, add1) == 2
|
|
assert then(None, add1) == None
|