- How did it go?
- Head/Tail/Init/Last: https://gist.github.com/gabebw/a6284db3d96612aae5a5
- Pattern Matching: https://gist.github.com/gabebw/a837caca1869ab4daafa
- Bonus: Fill in the Types: https://gist.github.com/gabebw/039ca8c2199372b811ba
http://learnyouahaskell.com/recursion
-
Recursive base case
-
Infinite recursion (
take 5 $ repeat 3
) - works because Haskell is lazy -
Pattern matching goes really well with recursion because the base case (or, in the book, edge condition) is more obvious
maximum' :: (Ord a) => [a] -> a
-- Error :(
maximum' [] = error "maximum of empty list"
-- Base case
maximum' [x] = x
-- Do the work
maximum' (x:xs) = max x (maximum' xs)
- With pattern matching:
zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x,y):zip' xs ys
http://learnyouahaskell.com/higher-order-functions
- Currying -
(a -> a -> a) = a -> (a -> a)
- Higher order functions,
map
,filter
- Sections:
(+ 4)
- Lambdas
- Folds (http://forum.upcase.com/t/reading-group-learn-you-a-haskell-part-two/1946/6)
- Function application with
$
- Function composition with
.
- Pointfree style
f xs = head xs
==f = head
, because laziness anda -> b -> c
is reallya -> (b -> c)
- Just 1 chapter: "Modules"
- HW: https://exercises.upcase.com/exercises/pointfree-style
- Really hard to navigate the website
brew install exercism
exercism configure --key=API_KEY
exercism fetch haskell
- README tells you how to run tests
exercism submit MyCoolThing.hs