1 implementation module Lambda
5 :: Term = C Value // constante v (C v)
6 | X Index // variabele x_i (X i)
7 | (@.) infixl 7 Term Term // applicatie (t1 t2) (t1 @. t2)
8 | \. Index Term // abstractie (\x_i . t) (\. i t)
9 :: Value :== Int // willekeurige integer waarde
10 :: Index :== Int // index (gebruikelijk i >= 0)
14 t2 = (\.0 (X 0)) // (\x_0 . x_0)
15 t3 = (\.0 (X 0)) @. (C 42) // (\x_0 . x_0) 42
16 t4 = (\.0 ((X 0) @. (X 0))) @. (\.1 ((X 1) @. (X 1))) // (\x_0 . x_0 x_0) (\x_1 . x_1 x_1)
17 t5 = (\.0 (\.1 (X 0))) // (\x_0 . (\x_1 . x_0))
18 t6 = (\.0 (\.1 (X 0))) @. (C 42) @. t4 // ((\x_0 . (\x_1 . x_0)) 42) ((\x_0 . x_0 x_0) (\x_1 . x_1 x_1))
20 terms = [t0, t1, t2, t3, t4, t5, t6]
22 instance toString Term where
25 Start = foldr (\s1 s2 -> s1 +++ "\n" +++ s2) "\n" (map toString terms)
30 //Start = map nf terms
33 vars :: Term -> [Index]
36 //Start = map vars terms
38 fresh :: [Term] -> Index
44 (<:) infixl 6 :: Term (Index,Term) -> Term
47 //Start = (((X 2) @. t1) @. (\.0 t1)) <: (0,C 50)
49 beta_reduce :: Term Term -> Term
52 //Start = beta_reduce (\.0 ((X 0) @. (X 0))) (\.0 ((X 0) @. (X 0)))
55 normal_order :: Term -> Term
58 applicative_order :: Term -> Term
63 , '\n', toString (normal_order t)
64 , '\n', toString (applicative_order t)
67 t = (\.0 (\.1 (X 0))) @. ((\.0 (X 0)) @. (C 42)) @. (C 50)
70 herschrijf :: (Term -> Term) Term -> Term
73 //Start = herschrijf normal_order t3