Skip to content

Commit 209dec1

Browse files
committed
---
yaml --- r: 663 b: refs/heads/master c: 43ec786 h: refs/heads/master i: 661: a8c2b46 659: 10ed396 655: 1902748 v: v3
1 parent c00ac34 commit 209dec1

File tree

2 files changed

+58
-43
lines changed

2 files changed

+58
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: bc646d01c501f2566fd78057e23c283cfedc0eb0
2+
refs/heads/master: 43ec78636fdbe3a01a0d2f97cbf1025c603b8b3e

trunk/doc/rust.texi

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ file.
325325
@sp 1
326326
@item Structural algebraic data types
327327

328-
The Rust type system is structural rather than nominal, and contains the
329-
standard assortment of useful ``algebraic'' type constructors from functional
330-
languages, such as function types, tuples, record types, vectors, and tagged
331-
disjoint unions. Structural types may be @emph{pattern-matched} in an
332-
@code{alt} statement.
328+
The Rust type system is primarily structural, and contains the standard
329+
assortment of useful ``algebraic'' type constructors from functional
330+
languages, such as function types, tuples, record types, vectors, and
331+
nominally-tagged disjoint unions. Such values may be @emph{pattern-matched} in
332+
an @code{alt} statement.
333333

334334
@sp 1
335335
@item Generic code
@@ -1667,6 +1667,7 @@ are no general parametric types.
16671667
* Ref.Item.Iter:: Items defining iterators.
16681668
* Ref.Item.Obj:: Items defining objects.
16691669
* Ref.Item.Type:: Items defining the types of values and slots.
1670+
* Ref.Item.Tag:: Items defining the constructors of a tag type.
16701671
@end menu
16711672

16721673
@node Ref.Item.Mod
@@ -1954,10 +1955,50 @@ values that are composite records, each containing two unsigned 8-bit
19541955
integers accessed through the components @code{x} and @code{y}, and laid
19551956
out in memory with the @code{x} component preceding the @code{y} component.
19561957

1957-
Some types are @emph{recursive}. A recursive type is one that includes
1958-
its own definition as a component, by named reference. Recursive types
1959-
are restricted to occur only within a single crate, and only through a
1960-
restricted form of @code{tag} type. @xref{Ref.Type.Tag}.
1958+
@node Ref.Item.Tag
1959+
@subsection Ref.Item.Tag
1960+
@c * Ref.Item.Type:: Items defining the constructors of a tag type.
1961+
@cindex Tag types
1962+
1963+
A tag item simultaneously declares a new nominal tag type
1964+
(@pxref{Ref.Type.Tag}) as well as a set of @emph{constructors} that can be
1965+
used to create or pattern-match values of the corresponding tag type.
1966+
1967+
The constructors of a @code{tag} type may be recursive: that is, each constructor
1968+
may take an argument that refers, directly or indirectly, to the tag type the constructor
1969+
is a member of. Such recursion has restrictions:
1970+
@itemize
1971+
@item Recursive types can only be introduced through @code{tag} constructors.
1972+
@item A recursive @code{tag} item must have at least one non-recursive
1973+
constructor (in order to give the recursion a basis case).
1974+
@item The recursively argument of recursive tag constructors must be @emph{box}
1975+
values (in order to bound the in-memory size of the constructor).
1976+
@item Recursive type definitions can cross module boundaries, but not module
1977+
@emph{visibility} boundaries, nor crate boundaries (in order to simplify the
1978+
module system).
1979+
@end itemize
1980+
1981+
An example of a @code{tag} item and its use:
1982+
@example
1983+
tag animal @{
1984+
dog();
1985+
cat();
1986+
@}
1987+
1988+
let animal a = dog();
1989+
a = cat();
1990+
@end example
1991+
1992+
An example of a @emph{recursive} @code{tag} item and its use:
1993+
@example
1994+
tag list[T] @{
1995+
nil();
1996+
cons(T, @@list[T]);
1997+
@}
1998+
1999+
let list[int] a = cons(7, cons(13, nil()));
2000+
@end example
2001+
19612002

19622003
@page
19632004
@node Ref.Type
@@ -2240,40 +2281,14 @@ vector is always bounds-checked.
22402281
@cindex Tag types
22412282
@cindex Union types, see @i{Tag types}
22422283

2243-
The @code{tag} type-constructor forms new heterogeneous disjoint union
2244-
types.@footnote{The @code{tag} type is analogous to a @code{data} constructor
2245-
declaration in ML or a @emph{pick ADT} in Limbo.} A @code{tag} type consists
2246-
of a number of @emph{variants}, each of which is independently named and takes
2247-
an optional tuple of arguments.
2248-
2249-
The variants of a @code{tag} type may be recursive: that is, the definition of
2250-
a @code{tag} type may refer to type definitions that include the defined
2251-
@code{tag} type itself. Such recursion has restrictions:
2252-
@itemize
2253-
@item Recursive types can only be introduced through @code{tag} types.
2254-
@item A recursive @code{tag} type must have at least one non-recursive
2255-
variant (in order to give the recursion a basis case).
2256-
@item The recursively-typed members of recursive variants must be @emph{box}
2257-
values (in order to bound the in-memory size of the variant).
2258-
@item Recursive type definitions can cross module boundaries, but not module
2259-
@emph{visibility} boundaries, nor crate boundaries (in order to simplify the
2260-
module system).
2261-
@end itemize
2262-
2263-
An example of a @code{tag} type and its use:
2264-
@example
2265-
type animal = tag(dog, cat);
2266-
let animal a = dog;
2267-
a = cat;
2268-
@end example
2269-
2270-
An example of a @emph{recursive} @code{tag} type and its use:
2271-
@example
2272-
type list[T] = tag(nil(),
2273-
cons(T, @@list[T]));
2274-
let list[int] a = cons(7, cons(13, nil()));
2275-
@end example
2284+
A @emph{tag type} is a nominal, heterogeneous disjoint union
2285+
type.@footnote{The @code{tag} type is analogous to a @code{data} constructor
2286+
declaration in ML or a @emph{pick ADT} in Limbo.} A @code{tag} @emph{item}
2287+
consists of a number of @emph{constructors}, each of which is independently
2288+
named and takes an optional tuple of arguments.
22762289

2290+
Tag types cannot be denoted @emph{structurally} as types, but must be denoted
2291+
by named reference to a @emph{tag item} declaration. @xref{Ref.Item.Tag}.
22772292

22782293
@node Ref.Type.Fn
22792294
@subsection Ref.Type.Fn

0 commit comments

Comments
 (0)