@@ -325,11 +325,11 @@ file.
325
325
@sp 1
326
326
@item Structural algebraic data types
327
327
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.
333
333
334
334
@sp 1
335
335
@item Generic code
@@ -1667,6 +1667,7 @@ are no general parametric types.
1667
1667
* Ref.Item.Iter :: Items defining iterators.
1668
1668
* Ref.Item.Obj :: Items defining objects.
1669
1669
* Ref.Item.Type :: Items defining the types of values and slots.
1670
+ * Ref.Item.Tag :: Items defining the constructors of a tag type.
1670
1671
@end menu
1671
1672
1672
1673
@node Ref.Item.Mod
@@ -1954,10 +1955,50 @@ values that are composite records, each containing two unsigned 8-bit
1954
1955
integers accessed through the components @code {x } and @code {y }, and laid
1955
1956
out in memory with the @code {x } component preceding the @code {y } component.
1956
1957
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
+
1961
2002
1962
2003
@page
1963
2004
@node Ref.Type
@@ -2240,40 +2281,14 @@ vector is always bounds-checked.
2240
2281
@cindex Tag types
2241
2282
@cindex Union types , see @i {Tag types }
2242
2283
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.
2276
2289
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 }.
2277
2292
2278
2293
@node Ref.Type.Fn
2279
2294
@subsection Ref.Type.Fn
0 commit comments