2. Purely functional
No hidden state, no side effects
Non-strict
Lazy
Referentially transparent
Can replace expressions with their values
Pattern Matching
Little did I know then
4. f a b = a + b
f 1 2 == 3
f :: Int -> Int -> Int
f a b = a + b
A f a b ulous example
5. 1 : 2 : 3 : []
[1, 2, 3]
head [1, 2, 3] == 1
head :: [a] -> a
head [] = error "empty"
head (x:xs) = x
Ahead of the game
6. zip [1,2,3] [4,5,6]
[(1,4), (2,5), (3,6)]
zip :: [a] -> [b] -> [(a,b)]
zip (x:xs) (y:ys) =
(x, y) : zip xs ys
zip _ _ = []
zip-a-Dee-Doo-Dah
7. First-class functions
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith f (x:xs) (y:xs) =
f x y : zipWith f xs ys
zipWith _ _ _ = []
zip = zipWith (,)
I Like Ike
Generalizing How We're Using Zip
8. addOne = (1 +)
addOne 5 == 6
zip = zipWith (,)
(+) :: Num a => a -> a -> a
addOne :: Num a => a -> a
Curry on my wayward sum
Moses Schönfinkel
10. class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
x /= y = not (x == y)
instance Eq MyType where
x == y = checkXYequality
Do it with Typeclass
11. f x y = x
f 1 undefined
Add indices to a list
zip xs [0..]
Laziness to infinity
12. fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
fib n = fibs !! n
A nod to the canon
13. Learn You a Haskell
Real World Haskell
haskellbook.com
CIS 194
Monad Challenges
A History of Haskell: Being Lazy With
Class
Resources