Backport from sid to buster
[hcoop/debian/mlton.git] / regression / unary.sml
1 datatype num = Z | S of num
2
3 val rec plus =
4 fn (n, Z) => n
5 | (n, S m) => S (plus (n,m))
6
7 val zero = Z
8 val one = S Z
9 val two = plus (one,one)
10
11 val rec times =
12 fn (_, Z) => Z
13 | (n, S m) => plus (n, times (n,m))
14
15 val square = fn n => times (n,n)
16
17 val four = square two
18
19 val sixteen = square four
20
21 val two56 = square sixteen
22
23 val rec fib =
24 fn Z => Z
25 | S Z => S Z
26 | S (S n) => plus (fib (S n), fib n)
27
28 val x = fib (S Z)
29