signature Prelude= sig exception Error of string val error : string -> 'a val mkRandom : int -> int -> int val time : ('a -> 'b) -> 'a list -> ('b * int) list end; functor PRELUDE() = struct exception Error of string; fun error s = raise Error s; local fun timeone f x = let val start = System.processtime() val result = f x in (result, System.processtime() - start) end; in fun time f = map (timeone f); end; (* Given a seed, mkRandom returns a psuedo-random number generator which takes an integer argument of one more than the maximum return value required. ( Linear Congruential, after Sedgewick, "Algorithms", Addison-Wesley, 1983, Chapter 3 pp 37-38.) *) fun mkRandom seed = let val r = ref seed val a = 31415821 val m = 100000000 fun f n = let val rand = (r := ((a * !r + 1) mod m); (!r * n) div m) in if n < 0 then rand + 1 else rand end in f end; fun max a b :int = if a > b then a else b fun min a b :int = if a < b then a else b exception Maxl exception Minl fun maxl [] = raise Maxl | maxl [a] = a | maxl (h :: t) = max h (maxl t) fun minl [] = raise Minl | minl [a] = a | minl (h :: t) = min h (minl t) fun sum [] = 0 | sum (h :: t) = h + sum t fun prod [] = 1 | prod (h :: t) = h * prod t fun times a b = a * b : int and plus a b = a + b : int and mult a b = a * b : real and add a b = a + b : real fun stringOfInt (i:int) = PolyML.makestring i; end;