Skip to content

Instantly share code, notes, and snippets.

@gabebw
Last active August 29, 2015 14:26
Show Gist options
  • Save gabebw/6d82919077ebdcdcda20 to your computer and use it in GitHub Desktop.
Save gabebw/6d82919077ebdcdcda20 to your computer and use it in GitHub Desktop.

LYAH Chapters 5 & 6

Homework

Chapter 5: Recursion

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

Chapter 6: Higher Order Functions

http://learnyouahaskell.com/higher-order-functions

Next Week

Exercism.io

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment