Submission deadline: Tuesday, November 29, 2016 at 23:59
We can encoding different data types in the untyped λ-calculus (Booleans, order pairs, natural numbers, list among others). An encoding of the natural numbers is the Church encoding based on the Church numerals. The aim of this programming assignment is to know an alternative encoding for the natural numbers.
The data type Expr
representing the λ-terms and
the betaEq
function are defined in Lennart
Augustsson's blog Simpler,
Easier! You can use the source code of this blog, given the
correspondents credit, of course!
import Numeric.Natural ( Natural ) import Test.QuickCheck ( (==>), Property, quickCheck ) eN :: Natural -> Expr ePred :: Expr eAdd :: Expr eMult :: Exprwhere using an encoding different to the Church encoding, the function
eN n
returns the λ-term associated
with the natural number n
, and the functions
ePred
, eAdd
and eMult
are
the λ-terms correspond to the operations of predecessor,
addition and multiplication, respectively.
The lab will be tested with the tests
function
predW :: Expr -> Expr addW, multW :: Expr -> Expr -> Expr propPred :: Natural -> Property propPred n = n > 0 ==> betaEq (predW $ eN n) (eN $ n - 1) propAdd :: Natural -> Natural -> Bool propAdd m n = betaEq (addW (eN m) (eN n)) (eN $ m + n) propMult :: Natural -> Natural -> Bool propMult m n = betaEq (multW (eN m) (eN n)) (eN $ m * n) tests :: IO () tests = do quickCheck propPred quickCheck propAdd quickCheck propMultThe
tests
function which use the QuickCheck library
(install the library from Hackage
and see the paper).
For running the tests
function, you must define
the functions predW
, addW
and
multW
. These functions are wrappers for the functions
ePred
, eAdd
and eMult
,
respectively.
(10%)
Before submitting your code, which includes your README, clean it up:
where
-clauses and let
-definitions).Submission is electronic. Send an email to asr(at)eafit(dot)edu(dot)co and attach a compressed file (.zip or .tar.gz) with your solution.
Your submission has to include the following:
Foundations of Functional Programming Languages |