zhaw-fup/Exercises/exercise-7/Lambda.hs
2024-06-16 23:49:48 +02:00

25 lines
585 B
Haskell

--------------------
-- Exercise 1
--------------------
-- Ja
-- Nein
-- Ja
-- Nein
data Term =
Nat Integer
| Abs String Term -- EAbs Abstraction
| Inv Term Term -- EApp Invocation (a.k.a. Application) of a function
| Var String -- EVar a variable
| Add
pretty x = case x of
(Abs name term) -> "L" ++ name ++ "." ++ pretty term
(Inv func param) -> "(" ++ pretty func ++ " " ++ pretty param ++ ")"
(Var name) -> name
Add -> "Add"
-- example
-- >>> pretty (Abs "x" $ Abs "y" $ Inv (Inv Add (Var "x")) (Var "y"))
-- "Lx.Ly.((Add x) y)"