All Projects → kekyo → TypeInferencer

kekyo / TypeInferencer

Licence: Apache-2.0 license
Algorithm W and Algorithm M in F#

Programming Languages

F#
602 projects
shell
77523 projects

Projects that are alternatives of or similar to TypeInferencer

Gluon
A static, type inferred and embeddable language written in Rust.
Stars: ✭ 2,457 (+7345.45%)
Mutual labels:  functional, type-inference
puma
Meta-programming framework for JavaScript based on LayerD concepts
Stars: ✭ 30 (-9.09%)
Mutual labels:  ast
astravel
👟 Tiny and fast ESTree-compliant AST walker and modifier.
Stars: ✭ 38 (+15.15%)
Mutual labels:  ast
treecko
A collection of functional and immutable helpers for working with tree data structures.
Stars: ✭ 31 (-6.06%)
Mutual labels:  functional
omakase
Java-based, plugin-oriented CSS3+ parser
Stars: ✭ 13 (-60.61%)
Mutual labels:  ast
iterum
Handling iterables like lazy arrays.
Stars: ✭ 28 (-15.15%)
Mutual labels:  functional
performance-decorator
🏇User behavior & Function execution tracking solution - 大型前端项目的用户行为跟踪,函数调用链分析,断点调试共享化和复用化实践
Stars: ✭ 39 (+18.18%)
Mutual labels:  ast
public
util toolkit for go.golang 通用函数包
Stars: ✭ 135 (+309.09%)
Mutual labels:  ast
redot
Graphviz dot file processor powered by plugins based on @unifiedjs
Stars: ✭ 60 (+81.82%)
Mutual labels:  ast
rector-cakephp
Rector upgrades rules for CakePHP
Stars: ✭ 18 (-45.45%)
Mutual labels:  ast
ocean
Programming language that compiles into a x86 ELF executable.
Stars: ✭ 164 (+396.97%)
Mutual labels:  ast
estree-to-babel
convert estree ast to babel
Stars: ✭ 23 (-30.3%)
Mutual labels:  ast
zio-http4s-example
For anyone who's struggling to put an http4s server together with ZIO
Stars: ✭ 19 (-42.42%)
Mutual labels:  functional
snap
Snap Programming Language
Stars: ✭ 20 (-39.39%)
Mutual labels:  functional
func-dependency-injection-go
Dependency injection example using higher order functions
Stars: ✭ 26 (-21.21%)
Mutual labels:  functional
astutils
Bare essentials for building abstract syntax trees, and skeleton classes for PLY lexers and parsers.
Stars: ✭ 13 (-60.61%)
Mutual labels:  ast
vallang
Generic immutable recursive data representation API targeted at source code models and more.
Stars: ✭ 28 (-15.15%)
Mutual labels:  functional
stream
Go Stream, like Java 8 Stream.
Stars: ✭ 60 (+81.82%)
Mutual labels:  functional
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-33.33%)
Mutual labels:  ast
rudash
Rudash - Lodash for Ruby Apps
Stars: ✭ 27 (-18.18%)
Mutual labels:  functional

Algorithm W and Algorithm M in F#

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

NuGet TypeInferencer CI build (main)

What is this?

This is a type inference implementation of both Algorithm W and Algorithm M written in F#.

Referenced articles:

  1. Algorithm W Step by Step
  2. Proofs about a Folklore Let-Polymorphic Type Inference Algorithm

The method of article 1 was implemented with care not to change it as much as possible.

Example

// NuGet package is available.
#r "nuget: TypeInferencer"

open TypeInferencer

// `let id = fun x -> x in id id`
let expr =
    ELet("id",
        EAbs("x", EVar "x"),
        EApp(EVar "id", EVar "id"))

// Type environment (is empty)
let env = TypeEnv []

// Do inferring with `Algorithm W` (top-down)
let actual = infer TopDown env expr

// Pretty printing
printfn "Expression: %s" (show expr)
printfn "Actual: %s" (show actual)

Results:

Expression: let id = fun x -> x in id id
Actual: a3 -> a3

How to play it

A playing guide is here:


Basic interface

Well-defined types

AST expression type:

type public Lit =
    | LInt of value:int32
    | LBool of value:bool

type public Exp =
    | EVar of name:string
    | ELit of literal:Lit
    | EApp of func:Exp * arg:Exp
    | EAbs of name:string * expr:Exp
    | ELet of name:string * expr:Exp * body:Exp
    | EFix of func:string * name:string * expr:Exp

Result type type:

type public Type =
    | TVar of name:string
    | TInt
    | TBool
    | TFun of parameterType:Type * resultType:Type

The inferencer:

type public InferAlgorithm =
    | TopDown
    | BottomUp

[<AutoOpen>]
module public Inferencer =
    let infer: InferAlgorithm -> TypeEnv -> Exp -> Type

Requirements

  • F# 6.0 or upper
  • NuGet package supported platforms:
    • net6.0
    • net5.0
    • netcoreapp3.1
    • netcoreapp2.1
    • netstandard2.1
    • netstandard2.0
    • net48
    • net461

License

Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo2)

License under Apache-v2.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].