datatype list = | nil | cons of (int, list) fun list_length(xs: list): int = case+ xs of | nil () => 0 | cons (_, xs) => 1 + list_length(xs) fun list_append(xs: list, ys:list): list = case+ xs of | nil () => ys | cons (x, xs) => cons(x, list_append(xs, ys)) implement main() = let val a = cons(1, cons(2, cons(3, cons(4, nil)))) val b = cons(5, cons(6, cons(7, cons(8, nil)))) val lena = list_length(a) val lenb = list_length(b) val () = printf("length a: %d\n", @(lena)) val () = printf("length b: %d\n", @(lenb)) val c = list_append(a, b) val lenc = list_length(c) val () = printf("length c: %d\n", @(lenc)) in () end