write-you-a-haskell/chapter7/poly_constraints
2015-01-28 09:10:42 -05:00
..
Env.hs initial commit 2015-01-05 02:54:15 -05:00
Eval.hs initial commit 2015-01-05 02:54:15 -05:00
Infer.hs poly_constraints: solver needs no State 2015-01-23 00:38:22 +01:00
Lexer.hs initial commit 2015-01-05 02:54:15 -05:00
LICENSE initial commit 2015-01-05 02:54:15 -05:00
Main.hs initial commit 2015-01-05 02:54:15 -05:00
Parser.hs initial commit 2015-01-05 02:54:15 -05:00
poly.cabal initial commit 2015-01-05 02:54:15 -05:00
Pretty.hs poly{,_constraints}: s/the the/the/ in error msg 2015-01-20 22:27:43 +01:00
README.md PolyML -> Poly 2015-01-07 14:26:12 -05:00
Syntax.hs initial commit 2015-01-05 02:54:15 -05:00
test.ml initial commit 2015-01-05 02:54:15 -05:00
Type.hs initial commit 2015-01-05 02:54:15 -05:00

Poly

A simple ML dialect with definitions, let polymorphism and a fixpoint operator. Uses syntax directed HM type inference.

To compile and run:

$ cabal run

Usage:

Poly> let i x = x;
i : forall a. a -> a

Poly> i 3
3

Poly> :type i
i : forall a. a -> a

Poly> :type let k x y = x;
k : forall a b. a -> b -> a

Poly> :type let s f g x = f x (g x)
s : forall a b c. ((a -> b) -> c -> a) -> (a -> b) -> c -> b

Poly> :type let on g f = \x y -> g (f x) (f y)
on : forall a b c. (a -> a -> b) -> (c -> a) -> c -> c -> b

Poly> :type let let_bound = i (i i) (i 3)
let_bound : Int

Poly> :type let compose f g = \x -> f (g x)
compose : forall a b c. (a -> b) -> (c -> a) -> c -> b

Poly> let rec factorial n = 
  if (n == 0) 
  then 1
  else (n * (factorial (n-1)));

Notes

Top level let declarations are syntatic sugar for nested lambda. For example:

let add x y = x + y;

Is semantically equivelant to:

let add = \x -> \y -> x + y;

Top level Let-rec declarations are syntatic sugar for use of the fix operator. For example:

let rec factorial n = if (n == 0) then 1 else (n * (factorial (n-1)));

Is semantically equivelant to:

let factorial = fix (\factorial n -> if (n == 0) then 1 else (n * (factorial (n-1))));

License

Released under MIT license.