asdlGen Reference Manual : Input Syntax : Type Definitions
Previous: Module Syntax
Next: Primitive Types

3.3. Type Definitions


definitions = {typ-id "=" type}
type = sum-type | product-type
product-type = fields
sum-type = constructor {"|" constructor}
["attributes" fields]
constructor = con-id [fields]
fields = "(" { field "," } field ")"
field = [id "."]typ-id ["?"| "*"] [id]

All type definitions occur within a module. They begin with a type identifier which is the name of the type. The name must be unique within the module. The order of definitions is unimportant. When translating type definitions from a module they are placed in what would be considered a module, package, or name-space of the same name. If a output language does not support such features and only has one global name space the module name is used to prefix all the globally exported identifiers.

Type definitions are either product types which are simple record definitions or sum type which represent a discriminated union of possible values. Unlike sum types, product types cannot form recursive type definitions, but they can contain recursively declared sum types.

3.3.1. Primitive Types

3.3.2. Product Types

3.3.3. Sum Types

3.3.3.1. The Rosetta Stone for Sum Types
3.3.3.2. Sum Types as Enumerations

3.3.4. Field Labels

3.3.5. Type Qualifiers

3.3.6. Attributes


asdlGen Reference Manual : Input Syntax : Type Definitions
Previous: Module Syntax
Next: Primitive Types