Previous Up Next

Chapter 10  Types, type equality, and subtyping

Moby is a typeful language and understanding its type system is a prerequesite to understanding the language.

10.1  Type schemes

TypeScheme
::= BoundTypeVarsopt Type
BoundTypeVars
::= [ BoundTypeVar (, BoundTypeVar)* ]
BoundTypeVar
::= TypeVar (<: Type)opt

10.2  Types

10.2.1  Type tuples

Types
::= TypeTuple
| Type
TypeTuple
::= ( (Type (, Type)+)opt )
Type tuples are used in the argument and result position of function types and in the argument position of data constructors.

10.2.2  Function types

Type
::= FunType
| AtomicType
FunType
::= AtomicTypes -> FunType
| AtomicTypes -> AtomicTypes
AtomicTypes
::= TypeTuple
| AtomicType
Note that the -> type constructor is right associative.

10.2.3  Atomic types

AtomicType
::= TypeVar
| NamedType
| $ TypeTuple

10.2.4  Type constructors

NamedType
::= Pathopt TypeId TypeArgsopt
| typeof ( NamedClass )
| # NamedClass
TypeArgs
::= ( Type (, Type)* )

10.2.5  Record types

RecordType
::= {| LabeledTypesopt |}
LabeledTypes
::= Label : ExtendedType (, Label : ExtendedType)*

10.2.6  Extended types

ExtendedType
::= TypeScheme
| var Type
Extended types are used in the specification of fields in record types (see Section 10.2.5) and object types (see Section 8.2). Using an extended type, one can specify that a field is polymorphic1 or that it is mutable. There three kinds of mutable fields: those annotated with the var keyword are simply updatable slots; those annotated with the ivar keyword are write-once fields with synchronous reading (these have so-called I-variable semantics); and those annotated with the mvar keyword are read/write cells with synchronous reading (these have so-called M-variable semantics).

10.2.7  Pervasive types

Moby provides the following pervasive types and type constructors:
Bool
Int
This type is the type of 32-bit 2's compliment signed integers.
Long
This type is the type of 64-bit 2's compliment signed integers.
Integer
This type is the type of arbitrary precision signed integers.
Float
This type is the type of IEEE Std 754-1985 single precision floating values.
Double
This type is the type of IEEE Std 754-1985 double precision floating values.
Extended
This type is the type of IEEE Std 754-1985 extended-double precision floating values. Note that the size of this type is system dependent.
Char
This type is the type of 8-bit ASCII characters.
Rune
This type is the type of 32-bit UNICODE characters.
String
This type is the type of immutable sequences of 8-bit characters.
Exn
This tagtype is the base tagtype for exception values.
Order
This enumeration type is used to denote the relation between elements of ordered types. It has the following definition:
enumtype Order { Less, Equal, Greater }
Option(t)
List(t)
Vector(t)
Array(t)
Ref(t)
Ptr(t)

10.3  Type equality

10.4  Subtyping


1
We call this ``almost first-class polymorphism.''

Previous Up Next