Type Definitions¶
In TorXakis, the user can define data types using the TYPEDEF keyword.
TorXakis will generate equality, type checking, and accessors functions for the user defined data types.
Syntax¶
typeDefs |
“TYPEDEF” typeDef (“;” typeDef)* “ENDDEF” |
typeDef |
typeName “::=” neConstructorList |
neConstructorList |
constructor (“|” constructor)* |
constructor |
constructorName (“{” neFieldsList “}”)? |
neFieldsList |
fields (“;” fields)* |
fields |
neFieldNameList “::” typeName |
neFieldNameList |
fieldName (“,” fieldName )* |
typeName |
|
constructorName |
|
fieldname |
Semantics¶
Examples¶
The statement
TYPEDEF Point ::= CPoint { x, y :: Int } ENDDEF
defines the data type Point as the Cartesian product of two integers. These integers are referred to as x and y.
The statement
TYPEDEF Conditional_Int ::=
CAbsent_Int
| CPresent_Int { value :: Int }
ENDDEF
defines the data type Conditional_Int as the union of the absence of a value and the presence of any integer value.
The statement
TYPEDEF List_Int ::=
CNil_Int
| Cstr_Int { head :: Int; tail :: List_Int } ENDDEF
defines the recursive data type List_Int as the union of the empty list and the list constructor: The Cartesian product of an integer referred to as head, and a List_Int referred to as tail.