Differences

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

Link to this comparison view

Next revision
Previous revision
pp:l08 [2017/05/08 10:22]
sergiu created
pp:l08 [2020/04/12 22:34] (current)
uvlad
Line 1: Line 1:
-===== Laborator 11 - Programare in Prolog ​=====+======= 8. The Lambda Calculus =======
  
-==== Multimi ==== +1Consider the following datatype which encodes λ-expressions:​
-  - Definiti predicatul ''​cartesian(L1,​L2,​R)''​ care construieste produsul cartezian al ''​L1''​ cu ''​L2''​ +
-  - Definiti predicatul ''​union(L1,​L2,​R)''​ care construieste reuniunea a doua multimi codificate ca liste. +
-  - Definiti predicatul ''​intersection(L1,​L2,​R)''​ +
-  ​Definiti predicatul ''​diff(L1,​L2,​R)''​ care construieste diferenta pe multimi intre ''​L1''​ si ''​L2''​+
  
-==== Permutari, Aranjamente,​ Combinari ==== +<code haskell>​ 
-  - Definiti predicatul ​''​pow(S,R)'' ​care construieste ​''​power-set''​-ul multimii ​''​S''​. +data LExpr Var Char | Lambda Char LExpr | App LExpr LExpr  
-  - Definiti predicatul ​''​perm(S,R)'' ​care genereaza toate permutarile lui ''​S''​. +</​code>​ 
-  - Definiti predicatul ​''​ar(K,S,R)'' ​care genereaza toate aranjamentele de dimensiune ​''​K'' ​cu elemente luate din ''​S''​ + 
-  Definiti predicatul ​''​comb(K,S,R)'' ​care genereaza toate combinarile de dimensiune ​''​K'' ​cu elemente luate din ''​S''​+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>​ 
 + 
 +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 x) y)'' ​produce?  
 + 
 +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)''​
 + 
 +8. Write a proper display function for these new constructors. 
 + 
 +9. Write a function ​''​luncurry'' ​which takes an uncurries λ-expression and transforms it in curry form. 
 +<code haskell>​ 
 +lcurry :: LExpr -> LExpr 
 +</​code>​ 
 + 
 +10. Write a function ​''​lcurry''​ which takes a curried λ-expression and transforms it in uncurry form. 
 +<​code>​ 
 +(((f xy) z)   ​becomes ​   (f x y z) 
 +(((f ((g a) b)) y) ((h u) v))  becomes ​ (f (g a b) y (h u v)) 
 +</​code>​  
 + 
 +11. Write the function ​''​fv'' ​which computes the list of all **free variables** of a λ-expression. 
 +<code haskell>​ 
 +fv :: LExpr -> [Char] 
 +</​code>​ 
 + 
 +12. Write a function ​''​bv'' ​which computes the list of all **bound variables** of a λ-expression. 
 +<code haskell>​ 
 +bv :: LExpr -> [Char] 
 +</​code>​ 
 + 
 +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>​ 
 +subst :: Char -> LExpr -> LExpr -> LExpr 
 +</​code>​ 
 + 
 +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>​ 
 +reduce :: LExpr -> LExpr 
 +</​code>​ 
 + 
 +15. Implement **normal-order** evaluation. 
 + 
 +16. Implement **applicative** (strict) evaluation.
  
-=== Solutii === 
-[[https://​github.com/​Programming-Paradigms/​Labs/​archive/​master.zip|Solutii]]