https://github.com/jglrxavpok/abstracttypeinference
A test project to try making abstract type inference
https://github.com/jglrxavpok/abstracttypeinference
calculus inference lambda lambda-calculus type
Last synced: about 2 months ago
JSON representation
A test project to try making abstract type inference
- Host: GitHub
- URL: https://github.com/jglrxavpok/abstracttypeinference
- Owner: jglrxavpok
- Created: 2017-03-12T20:51:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-10T15:24:59.000Z (almost 8 years ago)
- Last Synced: 2025-07-25T17:07:53.191Z (11 months ago)
- Topics: calculus, inference, lambda, lambda-calculus, type
- Language: Kotlin
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Abstract Type Inference
=======================
The goal of this library is to infer the type of a given expression made with simple blocks.
Elementary expressions
======================
Format: ```Expression type: KotlinConstructor(args)```
* Opaque expressions: ```OpaqueExpression(name)```
* Variable expressions: ```Variable(name)``` (similar to OpaqueExpression)
* Tuple expressions: ```Tuple(elements: Array)```, 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)```, all elements are of the same type
Elementary types
================
* 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)```
* List types: ```ListType(component: TypeDefinition)```
Rules for comparing elementary types
====================================
1. **All** types are <= than polyformic types.
2. Let a and b be two primitives types, ```a <= b iif a = b```
3. Let a and b be two function types, ```a <= b iif argument(a) <= argument(b) AND returnType(a) <= returnType(b)```
4. 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)```
5. Let a and b be two list types, ```a <= b iif component(a) <= component(b)```
6. Anything else is considered impossible comparisons and therefore issues an IllegalArgumentException
Discriminating types when inferring expressions
===============================================
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*.