Function Type
→ is an infix type constructor for functions
String → Number
A function with multiple → is a curried function
String → String → String
Slide 3
Slide 3 text
Universal Quantifiers
∀ (forall) is the universal quantifier and lowercase letters
stand for type variables
∀ a. a → a
㱺 expresses constraints on type variables
∀ a. Monoid a ⇒ a $-> a $-> a
Slide 4
Slide 4 text
Lambda function
\x y $-> x + y
Slide 5
Slide 5 text
Infix Operators
apply $:: forall a b. (a $-> b) $-> a $-> b
apply f x = f x
infixr 0 apply as $
applyFlipped $:: forall a b. a $-> (a $-> b) $-> b
applyFlipped x f = f x
infixr 1 applyFlipped as #
compose $:: forall a b c. (b $-> c) $-> (a $-> b) $-> a $-> c
compose f g x = f (g x)
infixr 9 compose as $$<<<
composeFlipped $:: forall a b c. (a $-> b) $-> (b $-> c) $-> a $-> c
composeFlipped f g = compose g f
infixr 9 compose as $$>>>
“if … then … else” is an expression
fact'' $:: Int $-> Int
fact'' n =
if n $== 0
then 1
else n * fact (n - 1)
Slide 17
Slide 17 text
Case expressions
fact $:: Int $-> Int
fact n =
case n of
0 $-> 1
_ $-> n * fact (n - 1)
Slide 18
Slide 18 text
Guards
fact $:: Int $-> Int
fact n
| n $== 0 = 1
| otherwise = n * fact (n - 1)
Slide 19
Slide 19 text
“let” and “where”
fact $:: Int $-> Int
fact 0 = 1
fact n =
let
acc = fact (n - 1)
in
n * acc
fact $:: Int $-> Int
fact 0 = 1
fact n = n * acc
where
acc = fact (n - 1)