CS 330 Lecture 29 – Functional
Agenda
- what ?s
- what makes a language functional
- Haskell
- expressions
- functions
- lists
- pattern matching
- partial function application
TODO
- Start the Funfun homework. Due before May 1.
- Pull down to get revised Funfun spec and fix in Timbre grader. See Piazza @16.
- No class on Friday.
- 1/4 sheet: Read first four chapters of Learn You a Haskell for a Great Good.
Code
Hello.hs
import Data.Char
a = 7
-- a = 0
-- initials :: [Char] -> [Char] -> [Char] -> [Char]
initials fname mname lname = head fname : head mname : head lname : []
capitalize :: [Char] -> [Char]
capitalize s =
if s == [] then
[]
else
toUpper (head s) : capitalize (tail s)
capitalize2 s
| s == [] = []
| otherwise = toUpper (head s) : capitalize2 (tail s)
capitalize3 s
case s of
[] -> []
(first:rest) -> toUpper first : capitalize2 rest
Haiku
on the science of naming things
“We’re out of letters
Greek’s used up. Hats and bars too.”
How math birthed CS
“We’re out of letters
Greek’s used up. Hats and bars too.”
How math birthed CS