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

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

staload "insort.sats"
dynload "insort.dats"

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

staload "selsort.sats"
staload _(*anon*) = "selsort.dats"
dynload "selsort.dats"

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

staload "libc/SATS/random.sats"

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

staload "contrib/testing/SATS/randgen.sats"
staload _(*anon*) = "contrib/testing/DATS/randgen.dats"
staload "contrib/testing/SATS/fprint.sats"
staload _(*anon*) = "contrib/testing/DATS/fprint.dats"

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

(*
** fun main (): void
*)

implement
main () = () where {
  #define N 10
  typedef T = int
//
  implement randgen<T> () = randint (100)
  implement fprint_elt<T> (out, x) = fprint (out, x)
//
  val () = srand48_with_time ()
//
  val xs = list0_randgen<T> (N)
  val () = print "xs = "
  val () = list0_fprint_elt<T> (stdout_ref, xs, ", ")
  val () = print_newline ()
  val ys = insort (xs)
  val () = print "ys = "
  val () = list0_fprint_elt<T> (stdout_ref, ys, ", ")
  val () = print_newline ()
//
  typedef T = int
  implement lte_selsort<T> (x, y) = x <= y
//
  val A = array0_randgen<T> (N)
  val () = print "A(bef) = "
  val () = array0_fprint_elt<T> (stdout_ref, A, ", ")
  val () = print_newline ()
  val () = selsort (A)
  val () = print "A(aft) = "
  val () = array0_fprint_elt<T> (stdout_ref, A, ", ")
  val () = print_newline ()
//
  typedef T = double
  implement randgen<T> () = drand48 ()
  implement fprint_elt<T> (out, x) = fprint (out, x)
  implement lte_selsort<T> (x, y) = x <= y
//
  val A = array0_randgen<T> (N)
  val () = print "A(bef) = "
  val () = array0_fprint_elt<T> (stdout_ref, A, ", ")
  val () = print_newline ()
  val () = selsort (A)
  val () = print "A(aft) = "
  val () = array0_fprint_elt<T> (stdout_ref, A, ", ")
  val () = print_newline ()
//
} // end of [main]

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

(* end of [test.dats] *)