[Spring,Summer,Fall,Winter]
2026-09-10
data declarations & type synonymselem, all, any)data declarationsdata declaration introduces a brand-new type with named constructorsRed, Green, Blue are values of type Color – not strings, not variablesderiving (...) asks GHC to auto-implement typeclass behavior for you
Enum/Bounded are why [minBound .. maxBound] :: [Color] worksSeason with four constructors, deriving Eq, Ord, Show, Enum, Bounded[minBound .. maxBound] :: [Season]type gives an existing type a new name -> it does NOT create a new typeName and String are interchangeable to GHCtype Age = Int)type Predicate = Int -> BoolisEven function by isEven :: Predicate and add one pattern determining an integer is an even number:t isEven (does it print Predicate or Int -> Bool?)a -> b -> c parses as a -> (b -> c)7
add 3 is a perfectly good value – a function still waiting for its second argumentcombine :: Int -> Int -> Int -> Int that adds three numbers:t combine 1 and :t combine 1 2 in ghci – what do you get back at each step?above 10 is a reusable one-argument function (“is greater than 10”)x instead, which is a much less reusable partial applicationbetween :: Int -> Int -> Int -> Bool where between lo hi x checks lo <= x && x <= hibetween 0 10? What does that partial application mean?\x -> <body> is a function with no name
10
double x = x + x (pattern-match syntax is sugar over a lambda)\ instead of named functionsisPositive n = n > 0 using a lambda instead of a named argument[1,2,3], using function elemFalse
True
add 3elem: check if the argument is in the provided foldablemap: apply a function to every element of a listall
map, apply a “function” to a foldable, where the function checks every element in the foldableanyall and even, write a check that every element of [2,4,6,8] is evenoldEnough age = age >= 18 – rewrite this point-freememberOfXs x = elem x xs (for some fixed list xs = [1,2,3]) – rewrite this point-free using lambda expressionsrunghc file.hs – run a script’s main, e.g. to see a whole test suite’s resultsghci file.hs – load a file, then poke at individual pieces interactively:t – e.g. check the type of a partial application before applying it furtherBrandeis Fall 2026 CS135 Recitation