4. History
September 1987 FPCA
“design by committee”
P. Hudak, J. Hughes, S. Peyton Jones, and
P. Wadler: “A History of Haskell: Being
Lazy With Class” (2007)
14. List Comprehensions
> let xs = [2,4,7]
> [ 2 * x | x <- xs ]
[4,8,14]
> [ even x | x <- xs ]
[True,True,False]
> [ 2 * x | x <- xs, even x, x > 3]
[8]
> [ x + y | (x,y) <- [(2,3),(2,1)] ]
[5,3]
> [ x + y | (x,y) <- [(2,3),(2,1)],
x < y ]
[5]
22. Higher Order Functions
patterns of computation
mapping: transforming elements
filtering: selecting elements
folding: combining elements
23. Mapping and Filtering
map :: (a -> b) -> [a] -> [b]
filter :: (a -> Bool) -> [a] -> [a]
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
24. Folding
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl1 :: (a -> b -> a) -> [b] -> a
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr1 :: (a -> a -> a) -> [a] -> a
25. Type Classes
type class: a collection of of types over
which certain functions are defined
equality class Eq
(==) :: (Eq a) => a -> a -> Bool
(/=) :: (Eq a) => a -> a -> Bool
26. Declaring a Class
class Visible a where
toString :: a -> String
size :: a -> Int
class Eq a where
(==), (/=) :: a -> a -> Bool
x /= y = not (x == y)
x == y = not (x /= y)
- FPCA: Conference on Functional Programming Languages and Computer Architecture
- Paul Hudak: Yale
- John Hughes: Chalmers (G&#xF6;teborg)
- Simon Peyton Jones: Microsoft Cambridge
- Philp Wadler: Edinburgh
- ghci demo
- exercises (1. Expressions, Values, and Types)
- exercises 2
- exercises 3
- warn about repeated variables
- generator
- one or more tests
- pattern
- exercises 4