// Main program demonstrating Lists
// AUTHOR: Gary T. Leavens

#include <iostream.h>
#include "CookList.h"

// An object of type inc_closure has
// an operation map that will map adding 1
// over a list of integers.
class inc_closure
  : public List_map<int, int> {
public:
    inc_closure() {}
    int the_proc(int x) { return x+1;}
};

// An object of type sum_closure has
// an operation flat_recur that will
// add up a list of integers.
class sum_closure
  : public List_flat_recur<int,int> {
public:
    sum_closure() {}
    int seed() { return 0; }
    int the_proc(int x, int y) {
      return x + y;
    }
};


int main()
{
  List<int>* my_list;
  my_list = new Nil<int>();
  my_list = new Cons<int>
    (3, new Cons<int>
     (4, new Cons<int>
      (5, new Nil<int>())));
  cout << *my_list << "\n" << flush;

  inc_closure ic;
  cout << *(ic.map(*my_list))
    << "\n"
    << flush;

  sum_closure sc;
  cout << sc.flat_recur(*my_list)
    << "\n"
    << flush;

  return 0;
}

/* expected output:
% ./a.out
(3 4 5)
(4 5 6)
12
*/
