CIS 554 -- Haskell Quiz Name __________________________________
  1. (5 points) In each of the following, write a single-line expression that computes the desired result. Do no error checking.

    1. Remove all the space characters (' ') from the string named line.

    2. Replace all the space characters (' ') in the string named line with asterisks ('*').

    3. Return True if the string named line contains an asterisk ('*').

    4. Return the smallest character (the one with the least ASCII value) in the string line. You may assume that line is not an empty string. (Hint: foldl1 and foldr1 do not require a starting value.)

    5. Given two strings line1 and line2 of equal length, return a string containing the smaller of each pair of corresponding characters. For example, given "haskell" and "clojure", return "caojele". (Hint: My solution uses zip, min, and a list comprehension.)

  2. (1 point) If f, g, and h are functions, and x and y are numbers, what is the difference between  f g h x y  and  f $ g $ h x y  ?

  3. (2 points) Give the type of each of the following expressions (as returned by :t in ghci).

    1. map

    2. flip map

  4. (1 point) Write an anonymous function to return the nth element of a nonempty list (counting the head of the list as element 1). Assume that the list contains at least n elements, that is, do no error checking.

  5. (1 point) Briefly describe how the IO monad allows Haskell to remain a "pure" functional language.