ListPair
structureThe ListPair structure provides operations on pairs of lists. These operations do not require that the lists have the same length; when the lists are of uneven lengths, the excess elements from the tail of the longer list are ignored.
signature LIST_PAIR
structure ListPair
: LIST_PAIR
val zip : ('a list * 'b list) -> ('a * 'b) list
val unzip : ('a * 'b) list -> ('a list * 'b list)
val map : ('a * 'b -> 'c) -> ('a list * 'b list) -> 'c list
val app : ('a * 'b -> unit) -> ('a list * 'b list) -> unit
val foldl : (('a * 'b * 'c) -> 'c) -> 'c -> ('a list * 'b list) -> 'c
val foldr : (('a * 'b * 'c) -> 'c) -> 'c -> ('a list * 'b list) -> 'c
val all : ('a * 'b -> bool) -> ('a list * 'b list) -> bool
val exists : ('a * 'b -> bool) -> ('a list * 'b list) -> bool
zip (l1, l2)
unzip l
zip
for equal length lists.
map f (l1, l2)
List.map f (zip (l1, l2))
.
app f (l1, l2)
List.app f (zip (l1, l2))
.
foldl f c (l1, l2)
foldr f c (l1, l2)
List.foldl f' c (zip (l1, l2))
and List.foldr f' c (zip (l1, l2))
where f' is fn ((a,b),c) => f(a,b,c)
.
all pred (l1, l2)
exists pred (l1, l2)
List.all pred (zip (l1, l2))
and List.exists pred (zip (l1, l2))
.
Rationale:
Another approach to these functions is to raise an exception when the argument lists are of uneven length. We chose not to do this, because comparing the lists for length conflicts with the short-circuit evaluation of
all
andexists
.
List
Last Modified April 8, 1996
Copyright © 1996 AT&T