PROGRAM 5
(* filename: prog10.sml author: anthony f. ortiz *) (* this program behaves like the system function map. *) fun mymap f nil = nil | mymap f (x :: y) = (f x) :: (mymap f y); mymap (fn x => 2 * x) [1, 2, 3]; mymap (fn x => x * x) [1, 2, 3]; mymap (fn x => x * x * x) [1, 2, 3]; (* filename: prog10.out author: anthony f. ortiz *) Standard ML of New Jersey, Version 110.0.6, October 31, 1999 [CM; autoload enabl ed] - use "prog10.sml"; [opening prog10.sml] val mymap = fn : ('a -> 'b) -> 'a list -> 'b list val it = [2,4,6] : int list val it = [1,4,9] : int list GC #0.0.0.0.1.9: (0 ms) val it = [1,8,27] : int list val it = () : unit - ^Z Stopped (user)
BACK TO CS6140 PAGE.