//
// Course: BU CAS CS 520
// Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu)
//

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

fun isEvn (x: int): bool =
  if x > 0 then isOdd (x - 1) else true

and isOdd (x: int): bool =
  if x > 0 then isEvn (x - 1) else false

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

// abst@ype ans_t = bool
typedef ans_t = bool
typedef cont (a: t@ype) = a -<cloref1> ans_t

fun kisEvn (x: int, k: cont bool): ans_t =
  if x > 0 then kisOdd (x - 1, k) else k (true)

and kisOdd (x: int, k: cont bool): ans_t =
  if x > 0 then kisEvn (x - 1, k) else k (false)

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

val K0 = lam (res: bool): ans_t =<cloref1> res

val ans = kisEvn (100, K0)
val () = (
  print ("kisEvn (100, \\res => res) = "); print ans; print_newline ()
) // end of [val]

val ans = kisOdd (100, K0)
val () = (
  print ("kisOdd (100, \\res => res) = "); print ans; print_newline ()
) // end of [val]

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

implement main () = ()

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

(* end of [evnodd.dats] *)