Grzegorz Bancerek

Paradigms of Programming in O'Caml

Exercises 1: Lists

  1. Define the test whether a list is empty.
  2. Define the length of a list.
  3. Define Fibonacci sequence as a list of n elements.
      let rec fibseq n = ...
    
  4. Define the sum of all elements from a list.
  5. Define the sum of squares of all elements from a list.
  6. Define the collective operation on f-images of all elements from a list.
      let rec collective (op:'a -> 'a -> 'b) (f:'c -> 'a) (l:'c list) = ...
    
  7. Define the test whether in a list there is an element satisfying given condition
      let rec exists (cond:'a -> bool) (l: 'a list) = ...
    
  8. Define the test whether all elements of a list satisfy given condition
      let rec all (cond:'a -> bool) (l: 'a list) = ...
    
  9. Insertion sort.
  10. Bubble sort.
  11. Selection sort.
  12. Merge sort.
  13. Quick sort.
  14. Heap sort.

bancerek@wi.pb.edu.pl