mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-22 14:38:20 +03:00
4e0fe22527
idris --fovm now gives a full defunctionalising compiler for a supercombinator language
31 lines
681 B
Plaintext
31 lines
681 B
Plaintext
data O 0
|
|
data S 1
|
|
|
|
fun plus(x, y) = case x of {
|
|
O => y
|
|
| S(k) => S (plus(k, y))
|
|
}
|
|
|
|
fun natToInt(x) = case x of {
|
|
O => 0
|
|
| S(k) => let y = natToInt(k) in y + 1
|
|
}
|
|
|
|
fun adder(arity, acc) = case arity of {
|
|
O => acc
|
|
| S(k) => adderAux(k, acc)
|
|
}
|
|
|
|
fun adderAux(k, acc, n) = adder(k, plus(acc, n))
|
|
|
|
fun zero() = O
|
|
fun one() = S(zero)
|
|
fun two() = S(one)
|
|
fun three() = S(two)
|
|
fun four() = S(three)
|
|
fun five() = S(four)
|
|
|
|
fun main() = %WriteInt(natToInt(adder(three, two, three, four, five)))
|
|
|
|
|