Standard ML of New Jersey (32-bit) v110.99 [built: Thu Dec 24 11:01:10 2020] - - Int.max; [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable] [autoloading done] val it = fn : int * int -> int - - - fun maxPairs ps = map Int.max ps; val maxPairs = fn : (int * int) list -> int list - - maxPairs [(2,3),(5,6),(1,0)] = [3,6,1]; val it = true : bool - - - - fun multPairs ps = map (fn (a,b) => a * b) ps; val multPairs = fn : (int * int) list -> int list - - multPairs [(2,3),(5,6),(1,0)] = [6,30,0]; val it = true : bool - - - fun multPairs ps = map (op *) ps; val multPairs = fn : (int * int) list -> int list - - multPairs [(2,3),(5,6),(1,0)] = [6,30,0]; val it = true : bool - - - fun multPairs ps = map * ps; stdIn:25.20-25.29 Error: operator and operand do not agree [overload - bad instantiation] operator domain: 'Z[OL(*)] * 'Z[OL(*)] operand: (('Y -> 'X) -> 'Y list -> 'X list) * 'W in expression: map * ps - - fun pairList xs = map (fn x => (x,x)) xs; val pairList = fn : 'a list -> ('a * 'a) list - - - pairList [1,2,3,4] = [(1,1),(2,2),(3,3),(4,4)]; val it = true : bool - - pairList [1,2,3,4]; val it = [(1,1),(2,2),(3,3),(4,4)] : (int * int) list - - pairList [1,2,3,4,3,2,1,0]; val it = [(1,1),(2,2),(3,3),(4,4),(3,3),(2,2),(1,1),(0,0)] : (int * int) list - - pairList ["cat","dog"]; val it = [("cat","cat"),("dog","dog")] : (string * string) list - - - - - foldl; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b - - foldr; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b - - - - foldr (op ::) [] [1,2,3,4,5]; val it = [1,2,3,4,5] : int list - - foldr (op ::) [] ["cat","dog","pear"]; val it = ["cat","dog","pear"] : string list - - - - foldr (fn (a,b) => (a,a)::b) [] [1,2,3,4,5]; val it = [(1,1),(2,2),(3,3),(4,4),(5,5)] : (int * int) list - - - fun dupList xs = foldr (fn (a,b) => (a,a)::b) [] xs; val dupList = fn : 'a list -> ('a * 'a) list - - - - - fun dupList xs = foldr (fn (a,b) => a::a::b) [] xs; val dupList = fn : 'a list -> 'a list - - dupList [1,2,3,4] = [1,1,2,2,3,3,4,4]; val it = true : bool - dupList [1,2,3,4]; val it = [1,1,2,2,3,3,4,4] : int list - - - fun dupList [] = [] = | dupList (x::xs) = x::x::dupList xs; val dupList = fn : 'a list -> 'a list - - dupList [1,2,3,4]; val it = [1,1,2,2,3,3,4,4] : int list - - - - - fun trueCount bs = foldr (fn (a,b) => if a then 1 + b else b) 0 bs; val trueCount = fn : bool list -> int - - trueCount [false,true,true,false,false,true,true]; val it = 4 : int - - - - - fun member x xs = foldr (fn (a,b) => if a=x then true else b) false xs; stdIn:75.42 Warning: calling polyEqual val member = fn : ''a -> ''a list -> bool - - - fun member (x:int) xs = foldr (fn (a,b) => if a=x then true else b) false xs; val member = fn : int -> int list -> bool - - - member 2 [1,2,3,4,5] = true; val it = true : bool - member 0 [1,2,3,4,5] = true; val it = false : bool - - member 0 [1,2,3,4,5] = false; val it = true : bool - - - fun member _ [] = false = | member x (y::ys) = if y=x then true else member x ys; stdIn:89.28 Warning: calling polyEqual val member = fn : ''a -> ''a list -> bool - - - member 0 [1,2,3,4,5] = false; val it = true : bool -