zhaw-fup/Exercises/exercise-7/Lambda.hs

36 lines
793 B
Haskell
Raw Normal View History

2024-06-16 22:02:00 +00:00
--------------------
-- Slides
--------------------
2024-06-16 22:01:19 +00:00
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
2024-06-16 22:02:00 +00:00
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)"
2024-06-16 21:49:48 +00:00
--------------------
-- Exercise 1
--------------------
-- Ja
-- Nein
-- Ja
-- Nein
2024-06-16 21:59:43 +00:00
--------------------
-- Exercise 2
--------------------
-- ((Lx.(x z)) (Ly.(x y)))
-- ((Lx.(x z)) (Ly.(w (Lw.(((w y) z) x)))))
-- (Lx.((x y) (Lx.(y x))))