teaching machines

CS 330 Lecture 33 – Map, Fold, Filter, Lambdas

April 21, 2014 by . Filed under cs330, lectures, spring 2014.

Agenda

TODO

Program This

Code

april21.hs

data Month = January | February | March | April | May | June | July | August | September | October | November | December deriving (Enum, Show, Read, Bounded)

-- quote sts = ["\"" ++ st ++ "\"" | st <- sts] 

convertMilesToKilometers [] = []
convertMilesToKilometers (first:rest) = (1.609 * first) : convertMilesToKilometers rest

quote [] = []
quote (first:rest) = ("\"" ++ first ++ "\"") : quote rest

map' f [] = []
map' f (first:rest) = f first : map' f rest

quoteOne s = "\"" ++ s ++ "\""
quote' strings = map' quoteOne strings

mult10 ns = map' (\n -> 10 * n) ns

bigs [] = []
bigs (first:rest)
  | first > 100 = first : bigs rest
  | otherwise = bigs rest

filter' f [] = []
filter' f (first:rest)
  | f first = first : filter' f rest
  | otherwise = filter' f rest

Haiku

Nerds learn fast, mostly
Part of Haskell trips them up
The social functions

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *