sdiehl / write-you-a-haskell

Building a modern functional compiler from first principles. (http://dev.stephendiehl.com/fun/)
MIT License
3.34k stars 256 forks source link

Inconsistency between poly/poly_constraints type inference #72

Closed sedwards-lab closed 7 years ago

sedwards-lab commented 8 years ago

In the process of implementing my own compiler, I found an inconsistency between the implementation of type inference between the poly and poly_constraints compilers in chapter 7.

I believe it has to do with the constraint generation around the "let" construct. In particular, let polymorphism doesn't seem to behave consistently.

A simple term that exhibits the problem is

let f = let add = \a b -> a + b in add

"poly" reports the type of "f" as "int -> int -> int," as it should be

"poly_constraints" reports it has type "forall a b c. a -> b -> c", which is too general.

sergei-mironov commented 7 years ago

Could you please also fix the text in http://dev.stephendiehl.com/fun/006_hindley_milner.html. I run into this issue as well.