Code Monkey home page Code Monkey logo

hm-infer-rs's Introduction

Hindley-Milner type inference for Scheme, in Rust

Port of hm-infer-scheme and hm-infer-cs.

This is a type inference engine built on the Hindley-Milner algorithm, that analyzes, type-checks and computes the type of expressions written in an extended subset of Scheme.

Supported Scheme constructs

  • (let ([name val] ...) body): basic let
  • (let* ([name val] ...) body): ordered let (each symbol can access the symbols defined before it)
  • (letrec ([name val] ...) body): let with recursion support (symbols can access themselves inside a lambda definition)
  • (lambda (a b ...) body): lambda definition
  • (head a b ...): procedure application (difference from Scheme: implicit partial application; such that (pair a b) is strictly equivalent to ((pair a) b))

Built-ins

Types:

  • int (Scheme number?)
  • bool (Scheme boolean?)
  • str (Scheme string?)
  • unit (void/unit type)
  • bottom (Haskell forall a. a, Rust !)

Symbols:

NameSignature (n-ary syntax)
Numbers+, -, *, /, modulo, succ, pred[int int] -> int
=[int int] -> bool
zeroint -> bool
Booleansand, or[bool bool] -> bool
Utilitieserrorstr -> never
if[bool a a] -> a
Pairspair[a b] -> (a * b)
car(a * b) -> a
cdr(a * b) -> b
Listsnil(list a)
cons[a (list a)] -> (list a)
hd(list a) -> a
tl(list a) -> (list a)
null?(list a) -> bool
Eitherlefta -> (either a b)
rightb -> (either a b)
either[(either a b) (a -> x) (b -> y)] -> (either x y)
Maybejusta -> (option a)
nothing(option a)
maybe[(option a) (a -> x)] -> (option x)

Internals

All functions are internally curried, as in Haskell, e.g. the type of pair is (a -> (b -> (a * b))). This allows for built-in support for partial application (cf. above) in the HM framework, while still allowing to define n-ary functions.

In effect, (lambda (a b) body) is syntactic sugar for (lambda (a) (lambda (b) body)).

hm-infer-rs's People

Contributors

zdimension avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.