Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Minimal type inference Algorithm W and Algorithm M in F#

License

NotificationsYou must be signed in to change notification settings

kekyo/TypeInferencer

Repository files navigation

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

NuGet TypeInferencerCI build (main)

What is this?

This is a type inference implementation of bothAlgorithm W andAlgorithm 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"openTypeInferencer// `let id = fun x -> x in id id`letexpr=    ELet("id",        EAbs("x", EVar"x"),        EApp(EVar"id", EVar"id"))// Type environment (is empty)letenv= TypeEnv[]// Do inferring with `Algorithm W` (top-down)letactual= infer TopDown env expr// Pretty printingprintfn"Expression:%s"(show expr)printfn"Actual:%s"(show actual)

Results:

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

How to play it

A playing guide is here:


Basic interface

Well-defined types

AST expression type:

typepublicLit=| LIntofvalue:int32| LBoolofvalue:booltypepublicExp=| EVarofname:string| ELitofliteral:Lit| EAppoffunc:Exp*arg:Exp| EAbsofname:string*expr:Exp| ELetofname:string*expr:Exp*body:Exp| EFixoffunc:string*name:string*expr:Exp

Result type type:

typepublicType=| TVarofname:string| TInt| TBool| TFunofparameterType:Type*resultType:Type

The inferencer:

typepublicInferAlgorithm=| TopDown| BottomUp[<AutoOpen>]modulepublicInferencer=letinfer:InferAlgorithm->TypeEnv->Exp->Type

Requirements

  • F# 6.0 or upper
  • NuGet package supported platforms:
    • net8.0
    • net7.0
    • 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.


[8]ページ先頭

©2009-2025 Movatter.jp