forked from avsm/EpiVM
-
Notifications
You must be signed in to change notification settings - Fork 10
/
testprogslow.e
45 lines (37 loc) · 988 Bytes
/
testprogslow.e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
include "Prelude.e"
main () -> Unit =
printInt(apply(natToInt, fact(nine())))
zero () -> Data = Con 0 ()
one () -> Data = Con 1 (zero())
two () -> Data = Con 1 (one())
three () -> Data = Con 1 (two())
four () -> Data = Con 1 (three())
five () -> Data = Con 1 (four())
six () -> Data = Con 1 (five())
seven () -> Data = Con 1 (six())
eight () -> Data = Con 1 (seven())
nine () -> Data = Con 1 (eight())
ten () -> Data = Con 1 (nine())
natToInt (x:Data) -> Int =
case x of {
Con 0 () -> 0
| Con 1 (k:Data) -> 1+natToInt(k)
}
plus (x:Data, y:Data) -> Data =
case x of {
Con 0 () -> y
| Con 1 (k:Data) -> Con 1 (plus(k, y))
}
mult (x:Data, y:Data) -> Data =
case x of {
Con 0 () -> Con 0 ()
| Con 1 (k:Data) -> plus(y, (mult(k, y)))
}
fact (x:Data) -> Data =
case x of {
Con 0 () -> one()
| Con 1 (k:Data) -> apply(mult(x), fact(k)) -- deliberate, to slow
-- down and test thunks
}
apply (f:Fun, a:Any) -> Any =
f(a)