Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ======= Lab 8 - The Lambda Calculus ======= 1. Consider the following datatype which encodes λ-expressions: <code haskell> data LExpr = Var Char | Lambda Char LExpr | App LExpr LExpr </code> Enroll ''LExpr'' in class ''Show''. 2. Write a function ''vars'' which returns a list of variables used in a λ-expression: <code haskell> vars :: LExpr -> [Char] </code> 3. Write a function ''reducible'' which tests if an expression can be reduced to another. **Write tests first!** What are the cases when an expression is reducible? <code haskell> reducible :: LExpr -> Bool </code> 4. Write a function which renames **all** occurrences of a variable with another, in a λ-expression: <code haskell> rename :: Char -> Char -> LExpr -> LExpr </code> 5. Write a function which **replaces all** occurrences of a variable with a λ-expression, in a λ-expression: <code haskell> replace :: Char -> LExpr -> LExpr -> LExpr </code> 4. Write a function which takes a λ-expression of the form ''(λx.<body> <arg>)'' and **reduces it in a SINGLE step**. - What should ''(λx.(x x) y)'' produce? - What should ''(λx.λx.(x x) y)'' produce? 5. Add two data constructors to the type ''LExpr'' so that we can also model functions and applications in uncurry form. Examples: ''(λx y z.<body>)'', ''(f x y z)''. 6. Write a proper display function for these new constructors. 7. Write a function ''lcurry'' which takes a curried λ-expression and transforms it in uncurry form. <code haskell> lcurry :: LExpr -> LExpr </code> 8. Write a function ''luncurry'' which takes an uncurries λ-expression and transforms it in curry form. Examples: ''( ((f x) y) z)'' becomes ''(f x y z)''. Also, ''( ((f ((g a) b)) y) ((h u) v))'' becomes ''(f (g a b) y (h u v))''