-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfib.mhs
More file actions
22 lines (19 loc) · 695 Bytes
/
fib.mhs
File metadata and controls
22 lines (19 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
value fib = \ n -> case n of
Zero -> Zero |
Succ Zero -> Succ Zero |
n -> add (fib (minus n (Succ Zero)))
(fib (minus n (Succ (Succ Zero))))
value main = Dialog ( \ resp ->
Cons Read (case resp of
Cons (ReadOK a) rest ->
Cons (Write (fib a)) Nil))
value minus = \ x y -> case Pair x y of
Pair x Zero -> x |
Pair (Succ x2) (Succ y2) -> minus x2 y2
value add = \ x y -> case Pair x y of
Pair x (Succ y2) -> add (Succ x) y2 |
Pair x Zero -> x
value mul = \ x y -> case Pair x y of
Pair x (Succ y2) -> add x (mul x y2) |
Pair x (Succ Zero) -> x |
Pair x Zero -> Zero