CSE536 Functional Programming                             Assignment # 1
Assigned: Wednesday Sept. 29, 2004        Due, in class: Wed Oct 6, 2004

 1)  Determine the types of "3", "even", and "even 3". How do you
     determine the last one?
 Now, determine the types of "head", "[1,2,3]", and "head [1,2,3]". What
     happens when applying a polymorphic function to an actual parameter?
  (hint, use the :t top level command of the Hugs interpreter).

 2) For each type, write a function with that type.

      a)   (Float -> Float) -> Float
      b)   Float -> (Float -> Float)
      c)   (Float -> Float) -> (Float -> Float)

 3 ) Write a function: strlen which returns the length of a string. E.G.
    strlen "abc"  --> 3           strlen ""  --> 0

    (hint: this is very easy, think what the type String is shorthand for.)

4) Write a function which computes n factorial. E.g.
   fact 0  --> 1     fact 3  --> 6    fact 5 --> 120

5) Write the ncopies function. For example:
   ncopies 3 5     --> [5,5,5]
   ncopies 4 "a"   --> ["a","a","a","a"]
   ncopies 0 true  --> []

6) Write the power function for integers. For example:

   power 5 2 --> 25        power 3 3 --> 27       power 2 5  --> 32

7) Write a function which converts a string of digits into an int.
   you will need the following predefined function:
        ord ‘1’       --> 49         first char in arg to its ascii code

   follow the following "pipeline" analysis when defining your function
   "167"  --> ['1','6','7'] --> [49,54,55] --> [1,6,7] --> [(1,100),(6,10),(7,1)]
   --> [100, 60, 7] --> 167
   (hint: the first function in the pipeline is very simple. why?)