-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLamb.hs
52 lines (43 loc) · 1.49 KB
/
Lamb.hs
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
{-
Module : Lamb
Description : Lambda calculus computer
Maintainer : [email protected]
Stability : experimental
This module computes beta reduction of untyped lambda terms.
Using the IO monad, the user is able to see the steps in
beta reduction.
-}
module Lamb where
import Lambda
import Church
import Alpha
import Beta
import System.IO
printStepsHelper :: LambdaTerm -> IO String
printStepsHelper t =
do
--putStrLn ("Current term: " ++ show t)
let nextTerm = betaReduction t
if (normalized t)
then
do
putStrLn ("Normalisation complete.")
putStrLn ("Upto alpha equivalence this term normalises to: ")
return (show (unAlphaReduction t))
else
do
--putStrLn ("= " ++ show nextTerm)
printStepsHelper nextTerm
printStepsToTerminal :: LambdaTerm -> IO ()
printStepsToTerminal t = printStepsHelper t >>= putStrLn
-- Example to be computed
example :: LambdaTerm
example = App suc (App (App add one) two)
example' :: LambdaTerm
example' = App neg (App (App disj tt) ff)
main :: IO ()
main =
do
let exampleTerm = (alphaReduction (App suc mulOfAdd))
putStrLn ("Normalising the following lambda term: \n " ++ (show exampleTerm))
printStepsToTerminal exampleTerm