Exam 1 Review

Joseph Haugh

University of New Mexico

Exam 1 Review

The exam covers chapters 1 through 4 from the textbook.

Topics

Definitions of basic concepts

  • What is a first class function?
  • What is functional programming?
  • What is currying?

Topics

Types of expressions

head ::

Topics

Types of expressions

head :: [a] -> a

Topics

Types of expressions

head :: [a] -> a
take ::

Topics

Types of expressions

head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 ::

Topics

Types of expressions

head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" ::

Topics

Types of expressions

head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" :: [Char]
fst (snd (1, ('a', "geralt"))) ::

Topics

Types of expressions

head :: [a] -> a
take :: Int -> [a] -> [a]
take 10 :: [a] -> [a]
take 10 "geralt" :: [Char]
fst (snd (1, ('a', "geralt"))) :: Char

Topics

Evaluating functions

head (tail "geralt") ===

Topics

Evaluating functions

head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" ===

Topics

Evaluating functions

head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 ===

Topics

Evaluating functions

head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 === 4
(\x y -> x + y) 3 4 ===

Topics

Evaluating functions

head (tail "geralt") === 'e'
"geralt" ++ " of " ++ "rivia" === "geralt of rivia"
(\x -> x + 1) 3 === 4
(\x y -> x + y) 3 4 === 7

Topics

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

Topics

allEven :: [Int] -> Bool
allEven []        = 

Topics

allEven :: [Int] -> Bool
allEven []        = True

Topics

allEven :: [Int] -> Bool
allEven []        = True
allEven [x]       = 

Topics

allEven :: [Int] -> Bool
allEven []        = True
allEven [x]       = even x

Topics

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