


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Last time we talked about functions and what they are. In Haskell, you can write programs which fail to terminate. We wrote: :t infinity = infinity a One of the features of Haskell program is polymorphism - an expression can have many types. So , infinity has all types. Often, we want to show functions have similar property.
Q:How to tell if functions are equal? A:Extensionality (pointwise equality)
Definition 1 Extensionality If f, g โ A โ B, f = g if and only if โx : A.f (x) = g(x)
This is introduced in discrete maths (COSC 2030). For any type we have three things:
For functions, the constructor is \x โ b is a function with one argument (x here) and defined by the expression b. The destructor for a function is function application - write name of the function next to the argument. For example, (\x โ b)a. The type notation is a โ b. The notation in Haskell is \xโ > x :: aโ > a.
The constructor for tuples is โ()โ brackets. The destructors for tuples are fst,snd and are defined as follows:
f st(a, b) = a snd(a, b) = b
The type notation is (a, b). In math, you use cartesian product of the form (a ร b).
The constructors for Bool are T rue, F alse. There are no destructors. And the type notation is Bool.
The constructor for list is [] - Empty list, and โ::โ - called cons. The destructors are head and tail and they have the types: head:: a list -> a tail:: a list -> a
About 1930, a guy named Alonzo Church invented a notation for a calculus of functions. This was called the lambda calculus. ฮ ::= x | \x.M | M N varibales abstraction application where M, N are lambda terms constructed by the above grammar. Alan Turing - student of Church - showed that Turing Machine are equivalent to lambda calculus. Churchโs thesis says
Everything that can in principle be computed can be computed by lambda- term Haskell Curry was working on logical systems called combinatory logic - turn out closely related to lambda calculus. Why was everyone working on it? Around 1920โs people were wondering about what can be computed. Curry noted that a propositional logic formula is valid (true) if and only if the type associated with the formula is โinhabitedโ by the ฮป-term. This is called the Curry-Howard isomorphism. So whatโs the translation? A โ B = A โ B A โง B = (A, B) A = A
Curry noticed the following
((A โง B) โ C) โ (A โ (B โ C)) (Currying) (A โง (B โ C)) โ ((A โง B) โ C)) (uncurrying)
We can do the translation as follows:
We can define curry in a new way as :
curryf = \x โ \y โ f (x, y) uncurryf = \p โ f (f st p) (snd p) uncurryf = (x, y) โ f x y
We can also do the following in Haskell
addc 5:: Int -> Int addc 5 5 :: Int