From c2ab01c161851508b3044c449c6f648f29026fe3 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 16 Jun 2024 23:47:06 +0200 Subject: [PATCH] Implement the `pretty` function --- Exercises/exercise-7/Lambda.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Exercises/exercise-7/Lambda.hs b/Exercises/exercise-7/Lambda.hs index 345d8db..a838fdf 100644 --- a/Exercises/exercise-7/Lambda.hs +++ b/Exercises/exercise-7/Lambda.hs @@ -4,3 +4,13 @@ data Term = | 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)"