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 TypeFieldDescription(package private) final Map<BuiltIn.BuiltInType, Type> final 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", ... n].Creates a "bag" type.Creates a bag type.Creates a binding of a type constructor value.(package private) DataTypedataType(String name, com.google.common.collect.ImmutableList<Type> argumentTypes, com.google.common.collect.ImmutableMap<String, Type.Key> tyCons) Creates 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.gReturns the "descending" built-in data type.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.lookup(BuiltIn.BuiltInType builtInType) Looks up a built-in type.Looks up a type by name, returning null if not found.lookupTyCon(String tyConName) Creates a multi-type.Creates a multi-type from an array of types.Creates an "option" type.order()Returns the "order" built-in data type.progressiveRecordType(Collection<Map.Entry<String, Type>> argNameTypes) Creates a progressive record type.progressiveRecordType(SortedMap<String, Type> argNameTypes) Creates a progressive record type.recordOrScalarType(Collection<Map.Entry<String, Type>> argNameTypes) Creates a record type, or returns a scalar type ifargNameTypeshas one entry.recordType(Collection<Map.Entry<String, Type>> argNameTypes) Creates a record type.recordType(SortedMap<String, ? extends Type> argNameTypes) Creates a record type.voidsetBuiltIn(BuiltIn.BuiltInType datatype) 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) unqualified(Type type) Removes any "forall" qualifier of a type, and renumbers the remaining type variables.Creates a "vector" type.private Type
-
Field Details
-
typeByName
-
builtInTypes
-
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
-
lookup
Looks up a built-in type.This is the only way to get internal built-in types (such as
BuiltIn.Datatype.PSEUDO_BOOL); non-internal built-in types (such asBuiltIn.Datatype.ORDERandBuiltIn.Datatype.OPTION) can also be retrieved 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. -
bagType
Creates a bag type. -
listType
Creates a list type. -
dataTypes
Creates several data types simultaneously. -
dataType
DataType dataType(String name, com.google.common.collect.ImmutableList<Type> argumentTypes, com.google.common.collect.ImmutableMap<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
-
setBuiltIn
Converts a regular type to an internal type. Throws if the type is not known. -
dataTypeScheme
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").Iteration order of the type constructors (
tyCons) is significant. We recommend that you use a sequenced map such asImmutableMaporLinkedHashMap. -
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.) -
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. -
progressiveRecordType
Creates a progressive record type. -
forallType
Creates a "forall" type. -
forallType
Creates a "for all" type. -
multi
Creates a multi-type from an array of types. -
multi
Creates a multi-type. -
unparseList
static StringBuilder unparseList(StringBuilder builder, Op op, int left, int right, Collection<? extends Type.Key> argTypes) -
unparse
-
typeVariables
-
unqualified
Removes any "forall" qualifier of a type, and renumbers the remaining type variables.Examples:
forall 'a. 'a list→'a listforall 'a 'b. 'b list→'a listforall 'a 'b 'c. 'c * 'a -> {x:'a, y:'c}→'a * 'b -> {x:b, y:a'}
-
lookupTyCon
-
apply
-
apply
-
typeVariable
Creates a type variable. -
descending
Returns the "descending" built-in data type. -
order
Returns the "order" built-in data type. -
bag
Creates a "bag" type."bag(type)" is shorthand for "apply(lookup("bag"), type)".
-
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.
-