Standard ML of New Jersey (32-bit) v110.99 [built: Thu Dec 24 11:01:10 2020] - - map; val it = fn : ('a -> 'b) -> 'a list -> 'b list - - map (fn x => x*x) [1,2,3,4,5]; val it = [1,4,9,16,25] : int list - - - map (fn x => 2*x) [1,2,3,4,5]; val it = [2,4,6,8,10] : int list - - - map String.size ["cat", "dog", "dogs", "apple", "pears"]; [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable] [autoloading done] val it = [3,3,4,5,5] : int list - - - map explode ["cat", "dog", "dogs", "apple", "pears"]; val it = [[#"c",#"a",#"t"],[#"d",#"o",#"g"],[#"d",#"o",#"g",#"s"], [#"a",#"p",#"p",#"l",#"e"],[#"p",#"e",#"a",#"r",#"s"]] : char list list - - - - filter; stdIn:15.1-15.7 Error: unbound variable or constructor: filter - - - fun filter h (x::xs) = xs; (* wrong *) stdIn:23.5-23.26 Warning: match nonexhaustive (h,x :: xs) => ... val filter = fn : 'a -> 'b list -> 'b list - - - fun filter h (x::xs) = if (h x) then x :: filter h xs else filter h xs; stdIn:26.5-26.71 Warning: match nonexhaustive (h,x :: xs) => ... val filter = fn : ('a -> bool) -> 'a list -> 'a list - - - fun filter h [] = [] = | filter h (x::xs) = if (h x) then x :: filter h xs else filter h xs; val filter = fn : ('a -> bool) -> 'a list -> 'a list - - - filter (fn x => x>=0) [2, ~2, 3, 4, ~5, ~5, ~8, 0, 1, ~2]; val it = [2,3,4,0,1] : int list - - filter (fn x => x<=0) [2, ~2, 3, 4, ~5, ~5, ~8, 0, 1, ~2]; val it = [~2,~5,~5,~8,0,~2] : int list -