-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.hs
31 lines (27 loc) · 1.31 KB
/
main.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
import PA1Helper
-- Same thing, but when printed Lexp's are easier to copy and paste into Haskell
-- import PA1HelperDebug
-- Haskell representation of lambda expression
-- In Lambda Lexp Lexp, the first Lexp should always be Atom String
-- data Lexp = Atom String | Lambda Lexp Lexp | Apply Lexp Lexp
-- Given a filename and function for reducing lambda expressions,
-- reduce all valid lambda expressions in the file and output results.
-- runProgram :: String -> (Lexp -> Lexp) -> IO()
-- This is the identity function for the Lexp datatype, which is
-- used to illustrate pattern matching with the datatype. "_" was
-- used since I did not need to use bound variable. For your code,
-- however, you can replace "_" with an actual variable name so you
-- can use the bound variable. The "@" allows you to retain a variable
-- that represents the entire structure, while pattern matching on
-- components of the structure.
id' :: Lexp -> Lexp
id' v@(Atom _) = v
id' lexp@(Lambda (Atom _) _) = lexp
id' lexp@(Apply _ _) = lexp
-- Entry point of program
main = do
putStrLn "Please enter a filename containing lambda expressions:"
fileName <- getLine
-- id' simply returns its input, so runProgram will result
-- in printing each lambda expression twice.
runProgram fileName id'