alice
library
manual.

Alice Project

The Pair structure


________ Synopsis ____________________________________________________

    signature PAIR
    structure Pair : PAIR
  

Common combinators on type 'a * 'b.

The type constructor pair is available in the top-level environment.

See also: Alt


________ Import ______________________________________________________

Imported implicitly.


________ Interface ___________________________________________________

    signature PAIR =
    sig
	type ('a,'b) pair = 'a * 'b
	type ('a,'b) t    = ('a,'b) pair

	val fst :     ('a,'b) pair -> 'a
	val snd :     ('a,'b) pair -> 'b

	val app :     ('a -> unit) * ('b -> unit) -> ('a,'b) pair -> unit
	val appFst :  ('a -> unit) -> ('a,'b) pair -> unit
	val appSnd :  ('b -> unit) -> ('a,'b) pair -> unit
	val map :     ('a -> 'c) * ('b -> 'd) -> ('a,'b) pair -> ('c,'d) pair
	val mapFst :  ('a -> 'c) -> ('a,'b) pair -> ('c,'b) pair
	val mapSnd :  ('b -> 'c) -> ('a,'b) pair -> ('a,'c) pair
	val mapSnd :  ('a -> 'b) -> ('a,'a) pair -> ('b,'b) pair

	val equal :   ('a * 'a -> bool) * ('b * 'b -> bool) -> ('a,'b) pair * ('a,'b) pair -> bool
	val collate : ('a * 'a -> order) * ('b * 'b -> order) -> ('a,'b) pair * ('a,'b) pair -> order
    end
  

________ Description _________________________________________________

type ('a,'b) pair = 'a * 'b
type t = pair

The type of cartesian products.

fst p
snd p

Returns the first (second) component of the pair p.

app (f,g) p
appFst f p
appSnd g p

The function app applies the functions f and g to the first and second component of the pair p, respectively. For the functions appFst and appSnd the following equivalences hold:

	appFst f p = app (f, ignore) p
	appSnd g p = app (ignore, g) p
map (f,g) p
mapFst f p
mapSnd g p

The function map produces a pair by mapping the functions f and g on both components of p. For the functions mapFst, mapSnd and mapBoth the following equivalences hold:

	mapFst f p  = map (f, id) p
	mapSnd g p  = map (id, g) p
	mapBoth f p = map (f, f) p

where id is the identity function.

equal (eqFst, eqSnd) (p1, p2)

Creates an equality function on pairs, given suitable equality functions for each component type.

collate (f, g) (p1, p2)

Performs lexicographic comparison of the two pairs using the given orderings f and g on the component types.



last modified 2007/Mar/30 17:10