-
Notifications
You must be signed in to change notification settings - Fork 10
/
Main.lhs
73 lines (67 loc) · 1.96 KB
/
Main.lhs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
> import Misc
> import Lambda
> import IdInt
> import Simple
> import Unique
> import HOAS
> import DeBruijn
> import DeBruijnC
> main :: IO ()
> main = interactArgs $
> \ args -> (++ "\n") . show . myNF args . toIdInt . f . read . stripComments
> where f :: LC Id -> LC Id -- just to force the type
> f e = e
> myNF ["U"] = Unique.nf
> myNF ["H"] = HOAS.nf
> myNF ["D"] = DeBruijn.nf
> myNF ["C"] = DeBruijnC.nf
> myNF ["S"] = Simple.nf
Timing in seconds on a MacBook processing the file {\tt timing.lam}.
\begin{center}
\begin{tabular}{|l|r@{.}l|}
\hline
Simple.nf & 8&3 \\
Unique.nf & 26&6 \\
HOAS.nf & 0&13 \\
DeBruijn.nf & 41&1 \\
DeBruijnEnv.nf & 41&1 \\
\hline
\end{tabular}
\end{center}
The $\lambda$-expression in {\tt timing.lam} computes
``{\tt factorial 6 == sum [1..37] + 17}'', but using Church numerals.
\mbox{}\\
\mbox{}\\
{\tt timing.lam:}
\begin{verbatim}
let False = \f.\t.f;
True = \f.\t.t;
if = \b.\t.\f.b f t;
Zero = \z.\s.z;
Succ = \n.\z.\s.s n;
one = Succ Zero;
two = Succ one;
three = Succ two;
isZero = \n.n True (\m.False);
const = \x.\y.x;
Pair = \a.\b.\p.p a b;
fst = \ab.ab (\a.\b.a);
snd = \ab.ab (\a.\b.b);
fix = \ g. (\ x. g (x x)) (\ x. g (x x));
add = fix (\radd.\x.\y. x y (\ n. Succ (radd n y)));
mul = fix (\rmul.\x.\y. x Zero (\ n. add y (rmul n y)));
fac = fix (\rfac.\x. x one (\ n. mul x (rfac n)));
eqnat = fix (\reqnat.\x.\y. x (y True (const False)) (\x1.y False (\y1.reqnat x1 y1)));
sumto = fix (\rsumto.\x. x Zero (\n.add x (rsumto n)));
n5 = add two three;
n6 = add three three;
n17 = add n6 (add n6 n5);
n37 = Succ (mul n6 n6);
n703 = sumto n37;
n720 = fac n6
in eqnat n720 (add n703 n17)
\end{verbatim}
\section{Conclusions}
This test is too small to draw any deep conclusions, but higher order
syntax looks very good. Furthermore, doing the simplest thing is not
necessarily bad.