| 1 |
-- main.mcl -- |
| 2 |
import "fmt" |
| 3 |
|
| 4 |
# TODO: should this be allowed? it means the func value has two different types! |
| 5 |
# this should be a polymorphic function as a value, iow a lambda |
| 6 |
$add = func($x) { |
| 7 |
$x + $x |
| 8 |
} |
| 9 |
|
| 10 |
$num = 2 |
| 11 |
$out1 = $add($num) # 4 |
| 12 |
|
| 13 |
test [fmt.printf("%d + %d is %d", $num, $num, $out1),] {} # simple math |
| 14 |
|
| 15 |
$val = "hello" |
| 16 |
$out2 = $add($val) # hellohello |
| 17 |
|
| 18 |
test [fmt.printf("%s + %s is %s", $val, $val, $out2),] {} # simple concat |
| 19 |
-- OUTPUT -- |
| 20 |
# err: errUnify: unify error with: topLevel(singleton(func(x) { call:_operator(str("+"), var(x), var(x)) })): type error: int != str |