alice
library
manual.

Alice Project

The Hole structure


________ Synopsis ____________________________________________________

    signature HOLE
    structure Hole : HOLE
  

The Hole structure provides operations to create and inspect holes. A hole is a place-holder for an undetermined value, reminiscent of a "logic" variable in logic programming. A hole is very much like a promise, but is transparent in its type. Filling a hole globally replaces the hole with a value. Unlike a future, accessing a hole does not imply synchronization, but causes the exception Hole to be raised (this includes calls to Future.status). It is possible to extract a future from a hole, though.

The use of the Hole structure is strongly discouraged! For most tasks, Promise is the prefarable choice, as it is safer from a typing point of view and compatible with concurrent programming. Holes should be considered a low-level concept.

See also: Future, Promise


________ Import ______________________________________________________

Imported implicitly.


________ Interface ___________________________________________________

    signature HOLE =
    sig
	exception Hole

	val hole :     unit -> 'a
	val future :   'a -> 'a

	val fill :     'a * 'a  -> unit
	val fail :     'a * exn -> unit

	val isHole :   'a -> bool
    end
  

________ Description _________________________________________________

exception Hole

Raised on any attempt to access a hole, and on any attempt to pass a non-hole to any of the functions in this structure.

hole ()

Creates a new hole and an associated future. Returns the hole.

future h

Returns the future associated with the hole h. If h is not a hole, h is returned.

fill (h, v)

Replaces the hole h and its associated future with the value v. If v is the hole or its future itself, the exception Future.Cyclic is raised instead. If h is not a hole, Hole is raised.

fail (h, ex)

Requests the exception ex, fails the future associated with the hole h with ex, and fills the hole with the same failed future. If h is not a hole, Hole is raised. Equivalent to

        (Future.await ex; fill (h, spawn raise ex))
isHole v

Returns true if v is a hole, false otherwise.



last modified 2007/Mar/30 17:10