//
// Course: BU CAS CS 520
// Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu)
//

(* ****** ****** *)

#define nil list_nil
#define cons list_cons
#define :: list_cons

(* ****** ****** *)

typedef T = int

(* ****** ****** *)

extern fun length {n:nat} (xs: list (T, n)): int n

implement length (xs) = case+ xs of
  | _ :: xs1 => 1 + length (xs1) | nil () => 0
// end of [length]

(* ****** ****** *)

extern fun append {m,n:nat}
  (xs: list (T, m), ys: list (T, n)): list (T, m+n)
// end of [append]

implement append (xs, ys) = case+ xs of
  | x :: xs1 => x :: append (xs1, ys) | nil () => ys
// end of [append]

(* ****** ****** *)

#define N 3

val xs1: list (T, N) = 1 :: 2 :: 3 :: nil ()

val () = assert (length xs1 = N)
val () = assert (length (append (xs1, xs1)) = N + N)

(* ****** ****** *)

implement main () = ()

(* ****** ****** *)

(* end of [list.dats] *)