(*
** Some code used in the lecture
*)

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

staload "genset.sats"

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

assume set (a:t@ype) = list0 (a)

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

(*
fun{a:t@ype} set_add (xs: set a, x: a): set a
*)

implement{a}
set_add (xs, x0) = let
  fun ins (xs: list0 a, x0: a): list0 a =
    case+ xs of
    | list0_cons (x, xs1) => let
        val sgn = compare<a> (x0, x)
      in
        if sgn <= 0 then list0_cons (x0, xs)
        else list0_cons (x, ins (xs1, x0))
      end
    | _ => list0_cons (x0, list0_nil)
in
  ins (xs, x0)
end // end of [set_add]

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

(* end of [genset.dats] *)