type 'a list = Nil | Cons of 'a * 'a list ;; type nat = Zero | S of nat ;; type 'a option = None | Some of 'a ;; let rec plus x y = match x with | Zero -> y | S(x') -> S(plus x' y) ;; let rec mult x y = match x with | Zero -> Zero | S(x') -> plus y (mult x' y) ;; let square x = mult x x ;; let rec unfoldr f z = match f z with | None -> Nil | Some(z') -> Cons(z',unfoldr f z') ;; let countdown m = match m with | Zero -> None | S(m') -> Some(m') ;; let enum n = match n with | Zero -> Nil | S(n') -> Cons(n, unfoldr countdown n) ;; let rec map f xs = match xs with | Nil -> Nil | Cons(x,xs') -> Cons(f x, map f xs') ;; let rec sum xs = match xs with | Nil -> Zero | Cons(x,xs') -> plus x (sum xs') ;; let sum_sqs n = sum (map square (enum n)) ;; ()