teaching machines

CS 330 Lecture 25 – Currying and The One-Liner

April 5, 2013 by . Filed under cs330, lectures, spring 2013.

Agenda

TODO

What Does This Do?

Code

today.hs


-- find' :: [(String, Integer)] -> String -> Maybe Integer 
find' [] needle = Nothing
find' (first:rest) needle
  | (fst first) == needle = Just (snd first)
  | otherwise = find' rest needle

ageBook = [("Sevy", 21), ("Chris", 32)]
getAge name =
  case find' ageBook name of Nothing -> "no such person"
                             Just age -> "this person is " ++ show age

cs330AgeBook = find' ageBook

-- getAge name = 
  -- case find' ageBook name of Nothing -> error "No such person" 
                             -- Just age -> age 

foldr' mix accum [] = accum
foldr' mix accum (first:rest) = mix first (foldr' mix accum rest)

-- and' list = foldr' (\item accum -> accum && item) True list 
-- or' list = foldr' (\item accum -> accum || item) False list 
and' = foldr' (&&) True
or' = foldr' (||) False
sum' = foldr' (+) 0
product' = foldr' (*) 1
reverse' = foldr' (:) []

Haiku

Got groceries once
Supper was bowls of flour
“You forgot the eggs”