#include "BUCASCS320.hats"
#define :: list0_cons
#define cons list0_cons
#define nil list0_nil
extern fun{elt:t@ype} list0_length (xs: list0 elt): int
implement{elt}
list0_length (xs) = loop (xs, 0) where {
fun loop (xs: list0 elt, res: int): int =
case+ xs of
| cons (_, xs1) => loop (xs1, res + 1)
| nil () => res
}
extern fun{elt:t@ype}
list0_append (xs: list0 elt, ys: list0 elt): list0 elt
implement{elt} list0_append (xs, ys) = append (xs, ys) where {
fun append (xs: list0 elt, ys: list0 elt): list0 elt =
case+ xs of
| list0_cons (x, xs) => list0_cons (x, append (xs, ys))
| list0_nil () => ys
}
extern fun{a,b:t@ype}
list0_zip (xs: list0 a, ys: list0 b): list0 @(a, b)
implement{a,b}
list0_zip (xs, ys) = case (xs, ys) of
| (list0_cons (x, xs), list0_cons (y, ys)) =>
list0_cons ((x, y), list0_zip (xs, ys))
| (list0_nil _, _) => list0_nil ()
| (_, list0_nil _) => list0_nil ()
typedef charlst = list0 char
extern fun
string_append (s1: string, s2: string): string
implement string_append (s1, s2) = let
val cs1 = string_explode (s1)
val cs2 = string_explode (s2)
val cs = list0_append<char> (cs1, cs2)
in
string_implode (cs)
end