alice
library
manual.

Alice Project

The Option structure


________ Synopsis ____________________________________________________

    signature OPTION
    structure Option : OPTION
  

An extended version of the Standard ML Basis' Option structure.

The type option and its constructors, the exception Option and the functions isSome, isNone, valOf and getOpt are available in the top-level environment.

See also: Alt


________ Import ______________________________________________________

Imported implicitly.


________ Interface ___________________________________________________

    signature OPTION =
    sig
	datatype 'a option = NONE | SOME of 'a
	type     'a t      = 'a option

	exception Option

	val equal :          ('a * 'a -> bool) -> 'a option * 'a option -> bool
	val collate :        ('a * 'a -> order) -> 'a option * 'a option -> order

	val isSome :         'a option -> bool
	val isNone :         'a option -> bool
	val valOf :          'a option -> 'a
	val getOpt :         'a option * 'a -> 'a

	val filter :         ('a -> bool) -> 'a -> 'a option
	val join :           'a option option -> 'a option
	val app :            ('a -> unit) -> 'a option -> unit
	val map :            ('a -> 'b) -> 'a option -> 'b option
	val mapPartial :     ('a -> 'b option) -> 'a option -> 'b option
	val fold :           ('a * 'b -> 'b) -> 'b -> 'a option -> 'b
	val compose :        ('a -> 'c) * ('b -> 'a option) -> 'b -> 'c option
	val composePartial : ('a -> 'c option) * ('b -> 'a option) -> 'b -> 'c option
    end
  

________ Description _________________________________________________

Items not described here are as in the Standard ML Basis' Option structure.

type t = option

A local synonym for type option.

isNone opt

Returns true if opt is NONE, false otherwise. This function is the negation of the function isSome.

fold f b opt

Returns f (v,b) if opt is SOME v, and b otherwise.

equal eq (opt1, opt2)

Creates an equality function on options, given a suitable equality function for the constituent type.

collate f (opt1, opt2)

Performs comparison on options, given a suitable ordering function f on the constituent type. The constructed ordering is defined as follows:

      fun collate f =
	  fn (NONE,   NONE)   => EQUAL
	   | (NONE,   SOME _) => LESS
	   | (SOME _, NONE)   => GREATER
	   | (SOME x, SOME y) => f (x, y)


last modified 2007/Mar/30 17:10