Skip to content

Instantly share code, notes, and snippets.

@Tonkpils
Created October 17, 2013 19:24

Revisions

  1. Tonkpils created this gist Oct 17, 2013.
    19 changes: 19 additions & 0 deletions pro.sml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    fun get_nth (words : string list, n : int) =
    if n = 1
    then (hd words)
    else get_nth((tl words), n - 1)

    fun date_to_string(date : int*int*int) =
    let
    val months = ["January", "February", "March", "April", "June",
    "July", "August", "September", "October", "November", "December"]
    val month = get_nth(months, #2 date)
    in
    month ^ " " ^ Int.toString(#3 date) ^ ", " ^ Int.toString(#1 date)
    end

    (* Find the error...*)
    (* - date_to_string((2013, 6, 1)) = "June 1, 2013" *)
    (* val it = false : bool *)
    (* - date_to_string((2013, 6, 1)); *)
    (* val it = "July 1, 2013" : string *)