Constrained Types

From dis-Emi-A

Jump to: navigation, search


Intro

Constrained types are motivated by the need to have better control over the values being stored in variables without being hinged directly to the native type limits. The type constraints thus also separates logical types completely from native types -- the compiler is responsible for selecting the appropriate native type.

Related to constrained types are Subtypes. The constraints on a type need to be added in a manner such that working with constrained and sub types is easy and natural.

Samples

 //a numeric value a, greater than 5 and less than or equal to 10
 : 5 < _ <= 10 : a

 //an enumerate value b, of one the three values
 : _ in [ "one", "two", "three" ] : b

 //a positive integer c
 Integer : _ >= 0 : c

The first examples demonstrate the standard use where the actual type of the variable is still left primarily undefined, only the constraints of the variable are defined. In the first case however it is clear that only a numeric types:numberic type matches such a constraint, though it may be Integeral, Real, or Complex still.

Personal tools