Exercises.

  1. Write an FP function to reverse a list.

  2. Write an FP function unique L. Unique accepts an input list, possibly infinitely long. It returns a list having the same members as L but with duplicates removed. The order of first occurrence must be maintained.
    eg.  unique ( 1::2::1::4::3::2:: ... )
       = 1::2::4::3:: ...
    

  3. A node in a binary tree can be represented as a triple: elt::left::right. Write a functional program to build a binary search tree from a list of elements.

  4. Extend the functional language parser to permit [a, b, c, ..., x] as a shorthand for a::b::c::...::x::nil and to allow "string" as shorthand for a list of characters ['s','t','r','i','n','g'].

  5. Add a where clause to the language.
    let [rec] <decs> in <Exp>  =  <Exp> where [rec] <decs>
    


[Previous Page] [Next Page] [Index] © L. Allison, Dept. of Computer Science, Monash University