You should read all the notes we have discussed so far (up to but NOT including list comprehensions), 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).
xs
(possibly using the same number on both sides).map
function and the filter
function.xss
returns the concatenation of all elements into a single list.n
.ss
whose length is at least 5.foldr
, foldl
using list comprehensions.($)
, specifying its type as well as its definition. Demonstrate with an example why one might want to use this operator instead of the normal function application (i.e. something like “f $ x
” instead of “f x
”).(.)
, specifying its type as well as its definition.x `mod` 2 == 1
.isOdd
that given a number returns whether the number is odd, and a function sum
that given a list of numbers returns their sum).IO
type) to do system input/output operations like printing? Why can’t a normal function of type say f :: Int -> Int
also do some IO operations?getChar
and putChar
.n
produces an action that asks the user to type in that many numbers and produces a list of those numbers.getChar
, putChar
and return
, as needed, write the following functions (also specify their type):
putStr
that given a string of characters prints that string.getLine
that reads characters until a newline is encountered, then returns the resulting string (excluding the newline).confirm
that expects the user to type y
or n
. If the user types one of those then the action produces the booleans True/False
respectively, otherwise it keeps reading more characters from the user.(<$>) :: (a -> b) -> IO a -> IO b
that is given a function and an action that produces an a
value, and returns a function that produces a b
value by performing the given action then applying the function to the resulting value.a
values at its nodes.
treeSum
that given such a binary tree adds up the values at the nodes. Make sure to correctly write the type for treeSum
, including the class constraint that the tree values can be added up.insert
which assuming that the content value type a
implements the Ord
class, takes in a new value and a tree that is a binary search tree and updates the tree with this new value inserted at the appropriate place. Make sure to correctly write the type for such a tree.maybeMin
that, assuming the tree is a binary search tree, locates the smallest value in the tree. It should return a Maybe a
value, with Nothing
if the starting tree was empty. Make sure to get the function type correctly, including the suitable type-class constraint.contains
that, given a value and a binary search tree determines if the tree contains the value. Make sure to get the function type correctly, including the suitable type-class constraint.foldr
and explain what each of the inputs does and what the function does overall. Also write down an implementation for foldr
.sum
and map
can be implemented via foldr
.any
and all
, and implement them via foldr
.Functor
type class and the Applicative
type class, and demonstrate the specific instance implementations of these for the type [a]
and the type Maybe a
.