[NEXT] [PREV]
HANDBOOK
/ GENTLE PRIMER
/ Describing Data
/Type Definitions 

Gentle
Applications Concepts Examples Handbook Support Download

A set of term values is introduced by a type definition.
For example,
the set of terms red, yellow, and blue
can be defined as a type Color
by the type definition
'type' Color red yellow blueA type definition gives the name of the type and lists the possible alternatives. If an alternative is given by a functor with arguments, then the types of the arguments are listed. For example, a type Signal is defined by 'type' Signal signal(Color, Color)A possible value of this type is signal(red, yellow). Type definitions may be recursive. E. g. a type ColorList can be defined by 'type' ColorList list(Color, ColorList) nilType definitions specify how to construct valid terms of a type: a value of a type may be obtained by replacing the type names in an alternative for that type by valid terms of the corresponding types. For example, since red is a Color and nil is a ColorList, one can choose the alternative list(Color, ColorList) and replace Color by red and ColorList by nil to obtain list(red, nil) as valid term of type ColorList. Using yellow as Color and the ColorList just constructed, one can build the more complex term list(yellow, list(red, nil)) of type ColorList. In a type definition the fields may be given names to document their meaning, e. g. list(Head: Color, Tail: ColorList) The terms considered so far are socalled ground terms: they do not contain variables as placeholders. A ground term is built from a simple functor without arguments or by taking already available ground terms and applying a functor to them, thus yielding a more complex term. 