CSC 8310 Linguistics of Programming Languages
Dr. David Matuszek
Fall 1997, Villanova University             Name:_____________________________________

Haskell Quiz

Consider the following BNF:

    <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
    <unop>  ::= neg
    <binop> ::= + | - | * | /
    <unit>  ::= <digit> | <unit> <unop> | <unit> <unit> <binop>
1. (3 points) Which of the following are a valid <unit>s? Write "yes" for valid <unit>s, "no" for things which are not <unit>s.
  1. 2 3 + 4 -       yes
  2. 3 6 + 9 12 - /       no
  3. 1 2 neg 3 neg       no
  4. 7 1 3 neg + 4 - 8 6 * / - 2      no
  5. 6 + 5 7 -       no
  6. 1 2 3 4 5 + - * / neg       yes
2. (1 point) Write a valid <unit> that is exactly eight (8) symbols long. Note that neg counts as a single symbol.
	1 2 3 + + 4 + neg		(all correct answers contain at least one neg)
	6 7 + 8  9 - neg +
	1 neg neg neg neg neg neg neg
3. (6 points) For each of the following expressions, what result is returned by Haskell?
  1. filter (`elem` "aeiou") "facetious"
          aeiou

  2. map (* 5) [1..5]
          [5, 10, 15, 20, 25]

  3. take 5 [x * x - 1 | x <- [1..]]
          [0, 3, 8, 15, 24]

  4. f 2 3 where f x y = x^2 + x*y
          10

  5. (\x -> [y | y <- [1..x], (mod x y) == 0]) 12
          [1, 2, 3, 4, 6, 12]

  6. :t [1, 2, 3]
          [1, 2, 3] :: [Int]