You should read all the notes we have discussed so far (up to but NOT including random numbers), and the corresponding textbook sections. These questions are here to help guide your studies, but are not meant to be exhaustive of everything you should know (though they do try to touch all the areas).
In all “coding” problems below, you must always include a type for each value/function/action you write.
Describe 5 ways in which Haskell differs from most other languages.
List at least 7 methods that operate on lists, write their type and explain what they do.
What are the differences between lists and tuples?
In Haskell a function that is meant to have two integer inputs can be written in two different ways. Describe those ways and the corresponding types for the function.
Write the types of the following functions, and describe their use: zip
, map
, filter
, (++)
, zip
, unzip
, take
, drop
. Write (possibly recursive) implementations for these functions.
Explain what parametric polymorphism and ad-hoc polymorphism are and how they differ. Provide concrete examples from any language other than Haskell you wish. Also describe how these two features are present in Haskell.
Describe what pattern matching is and provide examples. Be able to write functions that use pattern matching in various ways.
Describe what guards are and how they work. Give examples.
What are type aliases? What are custom data types? How do they differ?
Write list comprehensions to perform the following:
[(+), (*)]
) return a list of triples (x, y, z)
where x
and y
come from the list of integers, and z
is the result of applying one of the operators. The final result for a list with n
integers and a list with m
operators would have n*n*m
entries.[x,y..z]
syntax).Write operator sections for the following functions:
div
function)."!"
at the end of a string.'a'
(using the elem :: a -> [a] -> Bool
function).Use function composition and operator sections and/or direct functions to write functions that perform the following:
3x+2
for a given number x
.Write (recursive, maybe using pattern matching or guards, possibly with a helper) functions for the following:
Write IO actions, or functions producing IO actions, to perform the following (primitives you can use at putChar
, putStr
, putStrLn
, getLine
):
read
to turn a string into an integer) and returns it.f: a-> b
and an action IO a
create an action IO b
which uses the provided action to get an a
value, then uses f
to obtain a b
value and returns that.Provide the type and implementation for foldr
.
Implement the following using foldr
:
length
sum
and prod
(type [Int] -> Int
)and
and or
(type [Bool] -> Bool
)any
and all
(type (a->Bool) -> [a] -> Bool
)concat
(type [[a]] -> a
)