The goal of this library is to infer the type of a given expression made with simple blocks.
Format: Expression type: KotlinConstructor(args)
- Opaque expressions:
OpaqueExpression(name)
- Variable expressions:
Variable(name)
(similar to OpaqueExpression) - Tuple expressions:
Tuple(elements: Array<Expression>)
, must be used as an argument of a logically multi-argument function - Function expressions:
Function(name, argument: Expression, body: Expression)
- Function calls:
FunctionCall(function, argument)
- Literals:
Literal(userObject: Any, type: TypeDefinition)
, only expression to always have an explicit type - Lists:
List(elements: List<Expression>)
, all elements are of the same type
- Basic (or primitive) types:
TypeDefinition()
- Polymorphic types:
PolymorphicType()
(each polymorphic type has an UUID assigned on object creation) - Function types:
FunctionType(argument: TypeDefinition, returnType: TypeDefinition)
- Tuple types:
TupleType(elements: Array<TypeDefinition>)
- List types:
ListType(component: TypeDefinition)
- All types are <= than polyformic types.
- Let a and b be two primitives types,
a <= b iif a = b
- Let a and b be two function types,
a <= b iif argument(a) <= argument(b) AND returnType(a) <= returnType(b)
- Let a and b be two tuple types,
a <= b iif a and b have the same length AND for any valid index 'i', a(i) <= b(i)
- Let a and b be two list types,
a <= b iif component(a) <= component(b)
- Anything else is considered impossible comparisons and therefore issues an IllegalArgumentException
Let 'T' a non-empty list of types. The 'unified' type is min(T)
in respect of comparison rules from Rules for comparing elementary types.