SML# Document

Chapter 17. Types

This chapter defines the syntax for types and describes the built-in types.

Types are divided into monotypes (ty) and polytypes(polyTy). The syntax for mono types are given below.

ty ::= tyvar type variable names
 | {(tyrow)?} record types
 | ty1 *  * tyn tuple types (n2)
 | ty -> ty function types
 | (tySeq)? longTycon (parameterlized) datatypes
 | (ty)
tyraw ::= lab:ty (, tyraw)? record field types

tyvar are type variable names. As defined in Section 16.2, they are written as 'a'foo or ''a''foo. The latter form are for those equality type variables, which range only over types that admit equality. An type admits equality, called eqtype, is any type that does not contain function type constructor and built-in types that does not admit equality. A user defined datatype is an eqtype if it only contains eqtypes. For example, τ list defined below is an eqtype if τ is an eqtype.

datatype 'a list = nil | :: of 'a * 'a list

The function type constructor -> associates to the right so that int -> int -> int is interpreted as int -> (int -> int).

longTycon is a type constructor names defined by datatype declarations. Atomic types such as int are type constructors without type parameters (tySeq). SML#3.4.0 supports the following built-in atomic types and type constructors.

type constructor name description eqtype?
int 32 bit long signed integers Y
int64 64 bit long signed integers Y
int8 8 bit long signed integers Y
intInf unbounded signed integers Y
word 32 bit long unsigned integers Y
word64 64 bit long unsigned integers Y
word8 8 bit long unsigned integers Y
real floating point numbers) N
real32 32 floating point numbers N
char characters Y
string strings Y
exn exceptions N
unit unit values (()) Y
τ ref references (pointers) Y
τ array arrays Y
τ vector vectors Y

The syntax for polytypes (polyTy) are given below.

polyTy ::= ty
 | [boundtyvarList.ty]
 | ty -> polyTy
 | polyTy *  * polyTy
 | { (polyTyrow)? }
boundtyvarList ::= boundtyvar (, boundtyvarList)?
boundtyvar ::= tyvar(kind)?
kind ::= #{tyraw}
 | ::{tyList}
polyTyraw ::= lab:polyTy (, polyTyraw)?
  • [boundtyvarList.ty]は,束縛型変数boundtyvarList のスコープが明示された多相型である.

  • 束縛型変数は,その取りうる型の集合を制限する以下のカインド制約kindをつけることができる. レコードカインド#{ tyraw }は, tyrawが表すフィールドを含むレコード型に制限する. オーバロードカインド:: { tyList }は,インスタンス型tyListのいづれか に制限する.

The set of polytypes is the extension of the set of polytypes in the definition of Standard ML with record polymorphism, overloading and rank-1 polymorphism. The current system restricts overloading to system defined primitives, and type variables with overload kind are not allowed in a user program.

The following examples use a rank-1 polytype.

# fn x => (fn y => (x,y), nil);
val it = fn : ['a. 'a -> ['b. 'b -> 'a * 'b] * ['b. 'b list]]