(*
** Course: Concepts of Programming Languages (BU CAS CS 320)
** Semester: Summer I, 2009
** Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu)
*)

//
// Author: Hongwei Xi (hwxi AT cs DOT bu DOT edu)
// Time: Wednesday, June 22, 2009
//

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

#include "BUCASCS320.hats"

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

//
// singleton types:
// 0 : int(0), 1 : int(1), ...
// n : int(n) for each integer n
//

extern fun prstr_r (s: string): void

implement prstr_r (s) = let
  val s = string1_of_string (s) // string1_of_string: string -> string (n)
  fun loop {n,i:nat | i <= n} 
    (s: string n, n: size_t n, i: size_t i): void =
    if i < n then
      (print s[n-i-1]; loop (s, n, i+1))
    else ()
  // end of [loop]    
in
  loop (s, string_length s, 0)
end // end of [prstr_r] 

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

implement main () = () where {
  val () = prstr_r ("abcdefghijklmnopqrstuvwxyz")
  val () = print_newline ()
} // end of [main]

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

(* end of [code-2009-06-22.dats] *)