alice
library
manual.

Alice Project

The Package structure


________ Synopsis ____________________________________________________

    signature PACKAGE
    structure Package : PACKAGE
  

The Package structure provides functionality to construct and destruct packages. A package is a value encapsulating an arbitrary (higher-order) module and its signature. Packages enrich the static type system of ML with a dimension of dynamic typing: unpacking a package performs a dynamic type check. That basic mechanism is used to make safe all kinds of dynamic operations, particularly exchange of higher-order data structures between different processes (see structure Remote), or export to a file system (pickling).

The type package is available in the top-level environment.

See also: Pickle, Component, Compiler, Remote


________ Import ______________________________________________________

Imported implicitly.


________ Interface ___________________________________________________

    signature PACKAGE =
    sig
	type package
	type t = package

	type mismatch = Inf.mismatch
	exception Mismatch of mismatch

	functor Pack (signature S  structure X : S) : (val package : package)
	functor Unpack (val package : package  signature S) : S
	functor PackVal (type t  val x : t) : (val package : package)
	functor UnpackVal (val package : package  type t) : (val x : t)
    end
  

________ Description _________________________________________________

type package
type t = package

The type of packages. A package contains an arbitrary module and its signature.

type mismatch

A type containing the abstract description of the reason of a signature match failure.

exception Mismatch of mismatch

Raised upon failed attempts to unpack a package.

Pack (signature S = S structure X = X)

Creates a package encapsulating the module X under signature S. Returns a structure containing the package value as its only field. Equivalent to

	(val package = pack X : S)
Unpack (val package = package signature S = S)

Tries to unpack the package package. If the signature of the package matches S, the encapsulated module is returned. Otherwise, the exception Mismatch mismatch will be raised, with mismatch describing the reason for the failure. Equivalent to

	unpack package : S
PackVal (type t = t val x = v)

Creates a value package with signature (val x : t), encapsulating the value v under type t. Returns a structure containing the package value as its only field.

UnpackVal (val package = package type t = t)

Tries to unpack the value package package. If the type of the package is t, returns a structure containing the encapsulated value as its only field. Otherwise, the exception Mismatch will be raised.



last modified 2007/Mar/30 17:10