These are just some straightforward tests. If anyone has others, please post. Sign up for an account: http://www.wordpress.com . It’s quick and spam-free!

(* The following are a list of my tests
 * Each are one line (except a few at the bottom
 * and DO NOT EXECUTE THE ENTIRE FILE at once.
 *)
let fun f(x) = x in 13 end
let fun f(x) = x in f(13) end
(*make sure applying f not just returning 13*)
let fun f(x) = 7 in f(13) end
(*tail and nontail*)
let fun f(x) = let fun g(y) = x in g end in (f(13)) 7 end
(*binop*)
let val x = 4 + 2 in x end
let fun f(x) = 7 in f(13) + 5 end
let fun f(x) = 7 in 5 + f(13) end
let fun f(x) = let fun g(y) = x + y in g end in (f(13)) 7 end (*20*)
let fun f(x) = let fun g(y) = y + x in g end in (f(13)) 7 end (*20*)
(*anon funcs*)
val _ = (fn(x) => x) 13
let fun f(x) = (fn(y) => y + x) in (f(13)) 7 end
(*Unary funcs*)
val _ = ~(1 + 3)
(*tuple*)
let fun f(x) = 1 + x in (f(13), f(14), f(7), f(5)) end
(*Subscripts*)
val _ = #2 (5, 6, 7)
(*refs and order-of-eval-in-tuples/binops*)
val _ = ! (ref 0)
let val r = ref 0 val _ = (r := 1) val _ = (r := 2) in !r end
(* Should the following return 1 or 2? *)
let val r = ref 1
    fun setTwo(x) =
      let val _ = (r := 2)
      in 0
      end
in !r + setTwo()
end
(* Should the following return 1 or 2? *)
let val r = ref 1
    fun setTwo(x) =
      let val _ = (r := 2)
      in 0
      end
in setTwo() + !r
end

let val r = ref 1
    fun two(x) = (r := 2)
    fun five(x) = (r := 5)
in (!r, two(), !r, five(), !r)
end

(*ifthenelse*)
let fun fact(n) = if n < 1 then 1 else n * fact(n-1) in fact(4) end
(*Datatypes*)
let fun iotaHelper(x) =
      (case x
         of (0,l) => l
          | (n,l) => iotaHelper(n-1,Cons(n,l)))
in iotaHelper(3,Nil)
end
(* Non-exhaustive Case tests: *)
let fun test(p) =
      case p
        of 0 => 0 

in (test 0)
end
(* at this point you can try test-map.mml
 * SUGGESTION: change the noisy flag to false (cps-interp.sml line 382)
 * Otherwise, you'll be sitting around for hours ; )
 *)
Advertisements