Package net.hydromatic.morel.type
Class TypeSystem
java.lang.Object
net.hydromatic.morel.type.TypeSystem
A table that contains all types in use, indexed by their description (e.g.
"
int -> int").-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceProvides access to type variables from within a call toforallType(int, Function).private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal AtomicIntegerNumber of times thatTypedValue.discoverField(TypeSystem, String)has caused a type to change.final NameGenerator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareContiguousIntegers(Iterable<String> strings) Returns whether the collection is ["1", "2", ...Creates a binding of a type constructor value.(package private) DataTypeCreates an algebraic type.dataTypes(List<Keys.DataTypeKey> keys) Creates several data types simultaneously.Creates a data type scheme: a datatype if there are no type arguments (e.g.ensureClosed(Type type) Converts a type into aForallTypeif it has free type variables.Creates a function type.Creates a multi-step function type.forallType(int typeCount, Function<TypeSystem.ForallHelper, Type> builder) Creates a "forall" type.forallType(int typeCount, Type type) Creates a "for all" type.Creates a list type.Looks up a type by name.lookupInternal(String name) Looks up an internal type by name.Looks up a type by name, returning null if not found.lookupTyCon(String tyConName) Creates an "option" type.progressiveRecordType(SortedMap<String, ? extends Type> argNameTypes) Creates a progressive record type.recordOrScalarType(SortedMap<String, ? extends Type> argNameTypes) Creates a record type, or returns a scalar type ifargNameTypeshas one entry.recordType(SortedMap<String, ? extends Type> argNameTypes) Creates a record type.voidsetInternal(String name) Converts a regular type to an internal type.Creates a tuple type.Creates a tuple type from an array of types.Gets a type that matches a key, creating if necessary.Converts a list of keys to a list of types.Converts a map of keys to a map of types.typeVariable(int ordinal) Creates a type variable.typeVariables(int size) (package private) static StringBuilderunparse(StringBuilder builder, Type.Key type, int left, int right) (package private) static StringBuilderunparseList(StringBuilder builder, Op op, int left, int right, Collection<? extends Type.Key> argTypes) Creates a "vector" type.private Type
-
Field Details
-
typeByName
-
internalTypeByName
-
typeByKey
-
typeConstructorByName
-
nameGenerator
-
expandCount
Number of times thatTypedValue.discoverField(TypeSystem, String)has caused a type to change.
-
-
Constructor Details
-
TypeSystem
public TypeSystem()
-
-
Method Details
-
bindTyCon
Creates a binding of a type constructor value. -
wrap
-
lookupInternal
Looks up an internal type by name. -
lookup
Looks up a type by name. -
lookupOpt
Looks up a type by name, returning null if not found. -
typeFor
Gets a type that matches a key, creating if necessary. -
typesFor
Converts a list of keys to a list of types. -
typesFor
Converts a map of keys to a map of types. -
fnType
Creates a multi-step function type.For example,
fnType(a, b, c, d)returns the same asfnType(a, fnType(b, fnType(c, d))), viza → b → c → d. -
fnType
Creates a function type. -
tupleType
Creates a tuple type from an array of types. -
tupleType
Creates a tuple type. -
listType
Creates a list type. -
dataTypes
Creates several data types simultaneously. -
dataType
DataType dataType(String name, List<? extends Type> argumentTypes, SortedMap<String, Type.Key> tyCons) Creates an algebraic type.Parameter types is empty unless this is a type scheme. For example,
datatype 'a option = NONE | SOME of 'ahas parameter types and argument types['a], type constructors[NONE: dummy, SOME: 'a];int optionhas empty parameter types, argument types[int], type constructors[NONE: dummy, SOME: int];datatype color = RED | GREENhas empty parameter types and argument types, type constructors[RED: dummy, GREEN: dummy].
- Parameters:
name- Name (e.g. "option")argumentTypes- Argument typestyCons- Type constructors
-
setInternal
Converts a regular type to an internal type. Throws if the type is not known. -
dataTypeScheme
public Type dataTypeScheme(String name, List<TypeVar> parameters, SortedMap<String, Type.Key> tyCons) Creates a data type scheme: a datatype if there are no type arguments (e.g. "ordering"), or a forall type if there are type arguments (e.g. "forall 'a . 'a option"). -
recordOrScalarType
Creates a record type, or returns a scalar type ifargNameTypeshas one entry. -
recordType
Creates a record type. (Or a tuple type if the fields are named "1", "2" etc.; or "unit" if the field list is empty.) -
areContiguousIntegers
Returns whether the collection is ["1", "2", ... n]. -
progressiveRecordType
Creates a progressive record type. -
forallType
Creates a "forall" type. -
forallType
Creates a "for all" type. -
unparseList
static StringBuilder unparseList(StringBuilder builder, Op op, int left, int right, Collection<? extends Type.Key> argTypes) -
unparse
-
typeVariables
-
lookupTyCon
-
apply
-
apply
-
typeVariable
Creates a type variable. -
option
Creates an "option" type."option(type)" is shorthand for "apply(lookup("option"), type)".
-
vector
Creates a "vector" type."vector(type)" is shorthand for "apply(lookup("vector"), type)".
-
ensureClosed
Converts a type into aForallTypeif it has free type variables.
-