Standard ML of New Jersey (32-bit) v110.99 [built: Thu Dec 24 11:01:10 2020] - fun pairUp [] = [] (* base case of an empty list *) = | pairUp [x] = [] (* base case for a one-item list *) = | pairUp (x::y::ys) = (x,y) :: pairUp ys; val pairUp = fn : 'a list -> ('a * 'a) list - - - pairUp [1,2,3,4,5,6]; val it = [(1,2),(3,4),(5,6)] : (int * int) list - - pairUp ["cat","dog","apple","pear","dogs"]; val it = [("cat","dog"),("apple","pear")] : (string * string) list - - - fun pairUp [] = [] (* base case of an empty list *) = | pairUp (x::y::ys) = (x,y) :: pairUp ys; stdIn:16.5-17.43 Warning: match nonexhaustive nil => ... x :: y :: ys => ... val pairUp = fn : 'a list -> ('a * 'a) list - - pairUp [1,2,3,4,5,6]; val it = [(1,2),(3,4),(5,6)] : (int * int) list - - pairUp ["cat","dog","apple","pear","dogs","green"]; val it = [("cat","dog"),("apple","pear"),("dogs","green")] : (string * string) list - - pairUp [1,2,3,4,5]; uncaught exception Match [nonexhaustive match failure] raised at: stdIn:17.43 - - - fun pairUp [x] = [] (* base case for a one-item list *) = | pairUp (x::y::ys) = (x,y) :: pairUp ys; stdIn:31.5-32.43 Warning: match nonexhaustive x :: nil => ... x :: y :: ys => ... val pairUp = fn : 'a list -> ('a * 'a) list - - - pairUp [1,2,3,4,5]; val it = [(1,2),(3,4)] : (int * int) list - - pairUp ["cat","dog","apple","pear","dogs"]; val it = [("cat","dog"),("apple","pear")] : (string * string) list - - pairUp [1,2,3,4,5,6]; uncaught exception Match [nonexhaustive match failure] raised at: stdIn:32.43 - - - - [(1,2,3), (4,5,6), (7,8,9)]; val it = [(1,2,3),(4,5,6),(7,8,9)] : (int * int * int) list - - [(1,2,3), (4,5,6), (7,8,9), (4,5)]; stdIn:48.1-48.33 Error: operator and operand do not agree [tycon mismatch] operator domain: ('Z[INT] * 'Y[INT] * 'X[INT]) * ('Z[INT] * 'Y[INT] * 'X[INT]) list operand: ('Z[INT] * 'Y[INT] * 'X[INT]) * ('W[INT] * 'V[INT]) list in expression: (7,8,9) :: (4,5) :: nil - - [(1,2,3), (0,0), (4,5,6), (7,8,9)]; stdIn:50.1-50.32 Error: operator and operand do not agree [tycon mismatch] operator domain: ('Z[INT] * 'Y[INT]) * ('Z[INT] * 'Y[INT]) list operand: ('Z[INT] * 'Y[INT]) * ('X[INT] * 'W[INT] * 'V[INT]) list in expression: (0,0) :: (4,5,6) :: (7,8,9) :: nil - - - - - - fun tripleUp [] = [] (* base case of an empty list *) = | tripleUp [x] = [] (* base case for a one-item list *) = | tripleUp (x::y::z::zs) = (x,y,z) :: tripleUp zs = | tripleUp (x::y::ys) = (x,y) :: tripleUp ys; stdIn:58.27-58.47 Error: operator and operand do not agree [tycon mismatch] operator domain: ('Z * 'Z) * ('Z * 'Z) list operand: ('Z * 'Z) * ('Z * 'Z * 'Z) list in expression: (x,y) :: tripleUp ys - - - fun tripleUp [] = [] (* base case of an empty list *) = | tripleUp [x] = [] (* base case for a one-item list *) = | tripleUp (x::y::ys) = (x,y) :: tripleUp ys = | tripleUp (x::y::z::zs) = (x,y,z) :: tripleUp zs; stdIn:66.31-66.53 Error: operator and operand do not agree [tycon mismatch] operator domain: ('Z * 'Z * 'Z) * ('Z * 'Z * 'Z) list operand: ('Z * 'Z * 'Z) * ('Z * 'Z) list in expression: (x,y,z) :: tripleUp zs - - - fun tripleUp [] = [] (* base case of an empty list *) = | tripleUp [x] = [] (* base case for a one-item list *) = | tripleUp (x::y::ys) = (x,y,0) :: tripleUp ys = | tripleUp (x::y::z::zs) = (x,y,z) :: tripleUp zs; stdIn:70.6-73.53 Error: match redundant nil => ... x :: nil => ... x :: y :: ys => ... --> x :: y :: z :: zs => ... - - - fun tripleUp [] = [] (* base case of an empty list *) = | tripleUp [x] = [] (* base case for a one-item list *) = | tripleUp (x::y::z::zs) = (x,y,z) :: tripleUp zs = | tripleUp (x::y::ys) = (x,y,0) :: tripleUp ys; val tripleUp = fn : int list -> (int * int * int) list - - tripleUp [1,2,3,4,5,6,7,8]; val it = [(1,2,3),(4,5,6),(7,8,0)] : (int * int * int) list - - - - fun tripleUp [] = [] (* base case of an empty list *) = | tripleUp [x] = [] (* base case for a one-item list *) = | tripleUp (x::y::z::zs) = (x,y,z) :: tripleUp zs = | tripleUp (x::y::ys) = (x,y,y) :: tripleUp ys; val tripleUp = fn : 'a list -> ('a * 'a * 'a) list - - tripleUp [1,2,3,4,5,6,7,8]; val it = [(1,2,3),(4,5,6),(7,8,8)] : (int * int * int) list - - - - - fun zipUp ([], []) = [] = | zipUp ([], _) = [] (* base case for the first list *) = | zipUp (_, []) = [] (* base case for the second list *) = | zipUp (x::xs, y::ys) = (x,y) :: zipUp (xs, ys); val zipUp = fn : 'a list * 'b list -> ('a * 'b) list - - - zipUp ([1,2,3,4], ["cat","dog","apple"]); val it = [(1,"cat"),(2,"dog"),(3,"apple")] : (int * string) list - - - zipUp ([1,2,3,4], [1.1, 2.2, 3.3, 4.4, 5.5]); val it = [(1,1.1),(2,2.2),(3,3.3),(4,4.4)] : (int * real) list - - - - - fun zipPairUp ([], _) = [] (* base case for the first list *) = | zipPairUp (_, []) = [] (* base case for the second list *) = | zipPairUp ([x], _) = [] = | zipPairUp (_, [u]) = [] = | zipPairUp (x::y::ys, u::v::vs) = ((x,y),(u,v)) :: zipPairUp (ys, vs); val zipPairUp = fn : 'a list * 'b list -> (('a * 'a) * ('b * 'b)) list - - zipPairUp([1,2,3,4,5,6,7], [1.1,2.2,3.3,4.4,5.5,6.6]); val it = [((1,2),(1.1,2.2)),((3,4),(3.3,4.4)),((5,6),(5.5,6.6))] : ((int * int) * (real * real)) list - - - - - fun take (_, []) = [] (* base case for the list *) = | take (0, _) = [] (* base case for the number *) = | take (n, x::xs) = x :: take (n - 1, xs); val take = fn : int * 'a list -> 'a list - - - - take (3, [7,6,5,4,3,2,1]); val it = [7,6,5] : int list - take (23, [7,6,5,4,3,2,1]); val it = [7,6,5,4,3,2,1] : int list - take (0, [7,6,5,4,3,2,1]); val it = [] : int list - - - take (2, [1,2,3,3,2,1]); val it = [1,2] : int list -