[NEXT] [PREV]    HANDBOOK / LANGUAGE REFERENCE MANUAL /

Types

Gentle
Applications
Concepts
Examples
Handbook
Support
Download

TypeDecl = "'type'" Ident [["="] TermSpec{ [","] TermSpec}] .
TermSpec = IdentLC ["("[ParamSpec{ "," ParamSpec}]")"] .
ParamSpec = [Ident ":"] Ident .

Term Types

A type declaration
  • 'type' T
            f1 ( T1,1 , ... , T1,n1 )
            ...
            fm ( Tm,1 , ... , Tm,nm )
defines a type T and a set of values of that type. A value is called a term and is constructed by applying a functor fi to arguments. If Tau1, ... , Tauni are values of types Ti,1, ..., Ti,ni, then fi(Tau1 , ... , Tauni) is a value of type T.
   
Examples

'type' Color
   red, yellow, blue

Values of type Color are: red, yellow, and blue.


'type' List
   list(Color, List)
   nil

Values of type List include:
nil, list(red,nil), list(yellow(list(red,nil)).

A parameter specification may be written as

  • N : T
where N is an identifier documenting the meaning of the parameter.

   
Example

list(Head: Color, Tail: List)

Abstract Types

A type declaration without functor specifications introduces an abstract type. The values of such a type are not specified in Gentle.

   
Example

'type' IDENT

Basic Types

There are three basic types that may be used without being declared. The type INT comprises integer numbers. The type STRING comprises strings of characters. The type POS comprises source coordinates.





[NEXT] [PREV]