<!--
  - Authors:
  -   Denys Duchier <duchier@ps.uni-sb.de>
  -   Leif Kornstaedt <kornstae@ps.uni-sb.de>
  -   Christian Schulte <schulte@ps.uni-sb.de>
  -
  - Contributors:
  -   Daniel Simon <dansim@ps.uni-sb.de> (SGML Translation)
  -
  - Copyright:
  -   Denys Duchier, Leif Kornstaedt, and Christian Schulte, 1998
  -
  - Last change:
  -   $Date: 1999/01/21 09:52:39 $ by $Author: schulte $
  -   $Revision: 1.12 $
  -
  - This file is part of Mozart, an implementation of Oz 3:
  -   http://www.mozart-oz.org
  -
  - See the file "LICENSE" or
  -   http://www.mozart-oz.org/LICENSE.html
  - for information on usage and redistribution
  - of this file, and for a DISCLAIMER OF ALL
  - WARRANTIES.
  -
  -->

<Chapter id="chapter.typestruct">
  <Title/Type Structure and Description Format/
  <Section>
    <Title/Type Structure/
    <P>
      Types are sets of values of the &Oz; universe which share a common
      structure and common operations.  Types are divided into primary types
      and secondary types.
    <SubSection class=unnumbered>
      <Title/Primary Types/
      <P>
	<Index/primary types/<Index/types<And>primary/
	<Figure float id="figure.types" class=maxi>
	  <Caption>Standard Primary Types in &Oz;.</Caption>
	  <P>
	    <Picture.extern latex to="primary-types.tex">
	</Figure>
	The primary types of &Oz; are depicted in <Ptr to="figure.types">.
	Primary types provide a classification of values in the &Oz; Universe
	such that any two different subtypes of some primary type are disjoint.
	To check for a value to belong to a primary type, only its top-level
	constructor needs to be tested.  Note that implementations of &Oz; are
	free to introduce more primary types (so called <Def/extensions/) as
	immediate subtypes of either <Q/value/ or <Q/chunk/.
      <Para class=apropos><Title/Numbers/
	Numbers are either integers or floats.
      <Para class=apropos><Title/Literals/
	Literals are either atoms or names.
      <Para class=apropos><Title/Tuples/
	Tuples are special records whose features are the integers from
	1 to&nbsp;<Var type=meta/n/ for some integer&nbsp;<Var type=meta/n/,
	<<?{n} >= 0>>.
      <Para class=apropos><Title/Procedures/
	Procedures are classified according to their arity.  We speak about
	<Var type=meta/n/-ary procedures.
      <Para class=apropos><Title/Chunks/
	Chunks serve to represent abstract data structures.  They are defined
	similarly to records but provide only a restricted set of operations.
	This makes it possible to hide some or all of their features.  Typical
	chunks are objects and classes, locks and ports, and arrays and
	dictionaries.  There are chunks which do not belong to these types.
    <SubSection class=unnumbered>
      <Title/Secondary Types/
      <P>
	Secondary types are additional types for which &Oz; provides standard
	procedures or modules.
      <Para class=apropos><Title/Features/
	<Index/feature/<Def class=noindex/Features/ are either integers or
	literals.
      <Para class=apropos><Title/Pairs/
	A <Def/pair/ is a record matching <<'#'(_ _)>>.
      <Para class=apropos><Title/Lists/
	A <Def/list/ is either the atom <<nil>> or a record matching
	<<'|'(X Y)>> (or, equivalently, <<X|Y>>) such that <<Y>> is again
	a list.  Note that &Oz; allows cyclic lists which have an infinite
	unrolling.
      <Para class=apropos><Title/Property Lists/
	A <Def/property list/ is a list of pairs whose first component is a
	feature, &ie;, a literal or an integer.
      <Para class=apropos><Title/Virtual Strings/
	<Index/virtual string/<Def class=noindex/Virtual strings/ are used to
	encode strings.  Virtual strings contain atoms, strings, byte strings,
	integers, and floats, and are closed under tuple construction with the
	label&nbsp;<<'#'>>. For more details see <Ptr to="chapter.text">.
  <Section>
    <Title/Variable Status/
    <P>
      Each node&nbsp;?{X} in the store has exactly one of the following
      statuses: free, determined, future, or kinded.
    <Para class=apropos><Title/Free Variable/
      A variable&nbsp;<<X>> is <Def/free/ if the constraint store does not
      know anything about&nbsp;<<X>> apart from variable equalities <<X = Y>>.
    <Para class=apropos><Title/Determined Variable/
      A variable&nbsp;<<X>> is <Def/determined/ if the constraint store
      entails <<X = ?_{N}>> for some number&nbsp;?_{N}, or if it entails
      <<X = ?_{f}(?_{a1}: _ &ellipsis; ?_{an}: _)>> for some label&nbsp;?_{f}
      and the arity <<[?_{a1} &ellipsis; ?_{an}]>>, or if it entails
      <<X = ?{Y}>> for some byte string, procedure, cell, chunk, space or
      thread&nbsp;?_{Y}.
    <Para class=apropos><Title/Future/
      A variable&nbsp;<<X>> is <Def/future/ if the constraint store
      entails <<X = ?_{F}>> for some future&nbsp;?_{F}.
    <Para class=apropos><Title/Kinded Variable/
      A variable&nbsp;<<X>> is <Def/kinded/ if it is neither free nor
      determined nor future.
  <Section id="section.typestruct.format">
    <Title/Description Format/
    <P>
      Every standard procedure has an associated signature of the form
      <<<{Map ?+{Xs} ?+{P} ??{Ys}}>>>
      which specifies its arity, as well as types and modes of its arguments.
    <SubSection class=unnumbered>
      <Title/Types/
      <P>
	The type of an argument is indicated by its name, using the
	abbreviations summarized in the following table:
	<Table>
	  <TR/<TH/Abbreviation/<TH/Type//
	  <TR/<TD/?_{A}/<TD/atom//
	  <TR/<TD/?_{B}/<TD/bool//
	  <TR/<TD/?_{C}/<TD/chunk//
	  <TR/<TD/?_{F}/<TD/float//
	  <TR/<TD/?_{I}/<TD/integer//
	  <TR/<TD/?_{K}/<TD/class//
	  <TR/<TD/?_{L}/<TD/literal//
	  <TR/<TD/?_{N}/<TD/name//
	  <TR/<TD/?_{O}/<TD/object//
	  <TR/<TD/?_{P}/<TD/procedure//
	  <TR/<TD/?_{R}/<TD/record//
	  <TR/<TD/?_{S}/<TD/string//
	  <TR/<TD/?_{T}/<TD/tuple//
	  <TR/<TD/?_{U}/<TD/unit//
	  <TR/<TD/?_{V}/<TD/virtual string//
	  <TR/<TD/?_{X} ?_{Y} ?_{Z}/<TD/value//
	  <TR/<TD/?_{FI}/<TD/number//
	  <TR/<TD/?_{LI}/<TD/feature//
	  <TR/<TD/?_{AFI}/<TD/atom, float, or int//
	  <TR/<TD/?_{PO}/<TD/unary procedure or object//
	  <TR/<TD/?_{Xs}/<TD/lists of elements of type&nbsp;?_{X}//
	</Table>
	We use indices such as ?_{R1} or&nbsp;?_{R2} to disambiguate several
	occurrences of arguments of the same type.  We combine these
	abbreviations as in&nbsp;?_{FI} meaning <Q/float or integer/
	(&ie;, number) or ?_{LI} meaning <Q/literal or integer/ (&ie;,
	feature).  We use the plural-<Q/s/ suffix to indicate lists of
	values of a certain type.  For instance, ?_{Is} stands for a list
	of integers.  This suffix can be repeated to indicate lists of lists
	&etc;  Additionally, these arguments can be prefixed as in ?_{LowI},
	which indicates that the integer represents a lower bound.
    <SubSection class=unnumbered>
      <Title/Modes/
      <Para class=apropos><Title/Modes ?+{}, ??{}, none/
	The arguments of procedures can have one of four modes which are
	indicated by a symbol (?+{}, ??{}, none) attached to the arguments
	in the signature.
      <P>
	Modes indicate the synchronisation behaviour of a procedure.  The
	application of a procedure&nbsp;<<P>> waits until its inputs (?+{})
	are determined.  If the input arguments are well-typed, <<P>> will
	return outputs (??{}) of the specified types.  Ill-typed input
	arguments will raise a type error exception.  Types may be incompletely
	checked, especially those of of output arguments:  This happens when
	a value needs not be completely processed to perform an operation,
	&eg;, in <<List.dropWhile>>.
      <P>
	Occasionally, signatures of the base language will use the input
	mode&nbsp;?*{}.  Unless one uses any primitives from the constraint
	extensions, this is identical with&nbsp;?+{}.
    <SubSection class=unnumbered>
      <Title/Naming Conventions/
      <Para class=apropos><Title/Aliases/
      <P>
	Some of the standard values are so frequent that a special name is
	provided for them.  For example, <<List.map>> is also available as
	<<Map>>.  The signature of <<Map>> occurring in the description of
	module <<List>> (see <Ptr to="section.records.lists">) says that the
	procedure <<List.map>> is available via the abbreviation <<Map>>.
      <Para class=apropos><Title/Procedure Names/
	Given the signature
	<<<{?{procname} &ellipsis;}>>>
	in the description of the module <Var type=meta/module/, the procedure
	is available as:
	<List>
	  <Item>
	    <Var type=meta/procname/, provided <Var type=meta/procname/ is just
	    a variable;
	  <Item>
	    <Var type=meta/module/<<.>><Var type=meta/procname'/, where
	    <Var type=meta/procname'/ can be obtained from <Var type=meta
	    /procname/ by downcasing the first letter and deleting
	    the string <Var type=meta/module/.
	</List>
	For example, the test for lists is available as <<IsList>> and as
	<<List.is>>.
      <Para class=apropos><Title/Infix Notation/
	For very frequent procedures like arithmetic operations, there
	exists a convenient infix notation (see <Ptr to="chapter.infix">).
	By convention, the procedure names as they appear in the modules are
	the infix operators as atoms (&ie;, wrapped in quotes).  For instance,
	<<Number.'+'>> and <<Value.'&lt;'>> have an infix notation using the
	operators <<+>> and <<&lt;>>.
    <SubSection class=unnumbered>
      <Title/A Note on the Examples/
      <P>
	Several examples used in this document assume a unary procedure
	<Span class=index/<<Browse>>/ in the environment, which is supposed
	to display its argument value in a tool called <Def/browser/.
</Chapter>
