Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:l08 [2020/04/06 14:27]
pdmatei
pp:l08 [2020/04/12 22:34] (current)
uvlad
Line 1: Line 1:
-======= ​Lab The Lambda Calculus =======+======= 8The Lambda Calculus =======
  
 1. Consider the following datatype which encodes λ-expressions:​ 1. Consider the following datatype which encodes λ-expressions:​
Line 29: Line 29:
 </​code>​ </​code>​
  
-4. Write a function which takes a λ-expression of the form ''​(λx.<​body>​ <​arg>​)''​ and **reduces it in a SINGLE step**.+6. 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) y)''​ produce?
   - What should ''​(λx.λ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.+7. 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)''​. Examples: ''​(λx y z.<​body>​)'',​ ''​(f x y z)''​.
  
-6. Write a proper display function for these new constructors.+8. 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.+9. Write a function ''​luncurry''​ which takes an uncurries ​λ-expression and transforms it in curry form.
 <code haskell> <code haskell>
 lcurry :: LExpr -> LExpr lcurry :: LExpr -> LExpr
 </​code>​ </​code>​
  
-8. Write a function ''​luncurry''​ which takes an uncurries ​λ-expression and transforms it in curry form.+10. Write a function ''​lcurry''​ which takes a curried ​λ-expression and transforms it in uncurry ​form.
 <​code>​ <​code>​
 (((f x) y) z)   ​becomes ​   (f x y z) (((f x) y) z)   ​becomes ​   (f x y z)
Line 49: Line 49:
 </​code> ​ </​code> ​
  
-9. Write the function ''​fv''​ which computes the list of all **free variables** of a λ-expression.+11. Write the function ''​fv''​ which computes the list of all **free variables** of a λ-expression.
 <code haskell> <code haskell>
 fv :: LExpr -> [Char] fv :: LExpr -> [Char]
 </​code>​ </​code>​
  
-10. Write a function ''​bv''​ which computes the list of all **bound variables** of a λ-expression.+12. Write a function ''​bv''​ which computes the list of all **bound variables** of a λ-expression.
 <code haskell> <code haskell>
 bv :: LExpr -> [Char] bv :: LExpr -> [Char]
 </​code>​ </​code>​
  
-11. Write a function ''​subst''​ which computes the //textual substitution of all free occurrences of some variable x by e in e'//, according to the lecture definition:+13. Write a function ''​subst''​ which computes the //textual substitution of all free occurrences of some variable x by e in e'//, according to the lecture definition:
 <code haskell> <code haskell>
 subst :: Char -> LExpr -> LExpr -> LExpr subst :: Char -> LExpr -> LExpr -> LExpr
 </​code>​ </​code>​
  
-12. Implement a function which reduces a **reducible** λ-expression to an irreducible one. (According to the lecture definition, what happens with λx.(λx.x x) ?+14. Implement a function which reduces a **reducible** λ-expression to an irreducible one. (According to the lecture definition, what happens with λx.(λx.x x) ?
 <code haskell> <code haskell>
 reduce :: LExpr -> LExpr reduce :: LExpr -> LExpr
 </​code>​ </​code>​
 +
 +15. Implement **normal-order** evaluation.
 +
 +16. Implement **applicative** (strict) evaluation.
 +
 +