• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created almost 11 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An implementation of Hindley-Milner in Clojure.

hindley-milner

An implementation of Algorithm W (and an interpreter) for a simple lambda-calculus.

Assumptions

You have installed Leiningen and Git

Getting Set Up

Clone the repository:

git clone https://github.com/ericnormand/hindley-milner

cd hindley-milner

lein repl
user>

user> (ns user
        (:refer-clojure :exclude [eval])
        (:require [hindley-milner.syntax :refer :all]
		          [hindley-milner.eval :refer :all]
		          [hindley-milner.types :refer :all]))

Usage - Syntax

user> '(fn [a] x)

(fn [a] x)

user> (lambda? '(fn [a] x))

true

user> (free-vars '(let [a x
               b y]
            (((z a) b) c)))

#{'x 'y 'z 'c}

Usage - Evaluation

user> (interpret env 1)

1

user> (interpret env 
        '(let [c (dec b) 
		   id (fn a a) 
		   b 2] 
		(id c)))
		
1

Usage - Type Inference

user> (infer tenv 1)

:Integer

user> (infer* tenv '(if true 1 2))

[:Lambda :Integer]


user> (let [[_ [_] [_ [_ _ x] y]]
        (infer* tenv '(fn [a]
                        (let [x (fn [b]
                                  (let [y (fn [c]
                                            (a 1))]
                                    (y 2)))]
                          (x 3))))]
        (= x y))

true

Usage - Running Tests

To run the tests:

lein test

Goals

Pull requests welcome!

  • Implement Hindley-Milner in Clojure (DONE!)
  • Learn and teach about type systems
  • Discover similarities between Lisp's meta-circular eval and syntax-directed HM.

Non-goals

  • To type check Clojure.

TODO

  • Add support for inferencing multiple bindings in a let.
  • Add negative tests
  • Docstrings

License

Copyright Β© 2014 Eric Normand

Please see http://lispcast.com/Hindley-Milner-in-Clojure for rationale.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

grokking-simplicity-code

JavaScript
78
star
2

squarepeg

A peg parser in Clojure inspired by OMeta
Clojure
75
star
3

elm-frp

A Clojure/ClojureScript implementation of Elm FRP.
Clojure
57
star
4

playnice

A Clojure library to help build HTTP compliant servers.
Clojure
34
star
5

autoproxy

A couple of Clojure macros for creating anonymous instances.
Clojure
12
star
6

clj-reasoner

A simple graph reasoner written in Clojure.
Clojure
12
star
7

lispcast-clojure-core-async

Factory learning environment and code from LispCast Clojure core.async Videos.
Clojure
11
star
8

content.py

A Python script to scrape the content from web pages and leave the garbage.
Python
9
star
9

com.lispcast.core.specs

Homegrown specs for Clojure's built-in functions
Clojure
9
star
10

microkanren

Clojure
5
star
11

h5noir

HTML5 Boilerplate Comes to Noir framework
Clojure
4
star
12

spelling-jam

Code and data for the LambaJam 2013 Spelling Corrector Jam
Python
4
star
13

sphynx

Library for parsing dates, times, durations, and probably more in the future.
Clojure
3
star
14

ultra-docstrings

Replacement docstrings for Clojure, focusing on learning.
Clojure
3
star
15

clj-link-grammar

A link grammar parser written in Clojure.
Clojure
2
star
16

lisp-in-small-pieces

Clojure
2
star
17

coldplate

Templating library in Clojure.
Clojure
2
star
18

clj-peg

clj-peg has been renamed to "squarepeg"
2
star
19

clojureintro

Some code and slides for a presentation.
Clojure
1
star
20

solar-system

Smalltalk
1
star
21

cards2019

SImple card game framework for New Orleans Clojure Workshop 2019
Clojure
1
star
22

jvm-playground

Code to accompany the JVM Fundamentals for Clojure course on PurelyFunctional.tv.
Clojure
1
star
23

dw-scripts

Scripts I use for Democracy Works.
Clojure
1
star
24

clojurescript-strengths

Clojure
1
star
25

datahog

Transaction-safe graph data store built on SQL database.
Clojure
1
star