Joseph Haugh
University of New Mexico
The exam covers chapters 1 through 4 from the textbook.
Definitions of basic concepts
Types of expressions
head ::
Types of expressions
head :: [a] -> a
Types of expressions
head :: [a] -> a
take ::
Types of expressions
head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 ::
Types of expressions
head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" ::
Types of expressions
head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" :: [Char]
fst (snd (1, ('a', "geralt"))) ::
Types of expressions
head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" :: [Char]
fst (snd (1, ('a', "geralt"))) :: Char
Evaluating functions
head (tail "geralt") ===
Evaluating functions
head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" ===
Evaluating functions
head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 ===
Evaluating functions
head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 === 4
(\x y -> x + y) 3 4 ===
Evaluating functions
head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 === 4
(\x y -> x + y) 3 4 === 7
Writing functions
Write a function, allEven
, which returns True
if and only if all elements of the given list are even.
You can assume that the list will contain no more than
3 elements.
allEven :: [Int] -> Bool
allEven :: [Int] -> Bool
allEven [] =
allEven :: [Int] -> Bool
allEven [] = True
allEven :: [Int] -> Bool
allEven [] = True
allEven [x] =
allEven :: [Int] -> Bool
allEven [] = True
allEven [x] = even x
allEven :: [Int] -> Bool
allEven [] = True
allEven [x] = even x
allEven [x, y] = even x && even y
allEven [x, y, z] = even x && even y && even z