(module t2_length
  (data List (vars a)
    (ctor Nil)
    (ctor Cons a (con List)))
  (fn length
    (doc "Count the elements in a List a.")
    (type (fn-type (params (con List)) (ret (con Int)))
    (params xs)
    (body (match xs
      (case (pat-ctor Nil) 0)
      (case (pat-ctor Cons _ t) (app + 1 (app length t))))))
  (fn main
    (doc "Print length(Nil) and length(Cons(7, Cons(8, Cons(9, Nil))))).")
    (type (fn-type (params) (ret (con Unit)) (effects IO)))
    (params)
    (body (seq (do io/print_int (app length (ctor List Nil)))
      (do io/print_int (app length (ctor List Cons 7 (ctor List Cons 8 (ctor List Cons 9 (ctor List Nil))))))))))
