Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hindley-Milner Type Inference

5 views
Skip to first unread message

Jon Harrop

unread,
Feb 24, 2010, 7:35:53 AM2/24/10
to

I'd like to implement the HM type system with type inference in my language
front-end. I once lashed together something that seemed to work but, given
the theoretical foundation behind this, I'd like to follow some more
rigorous guidance this time.

I found an interesting draft paper "Algorithm W Step by Step":

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7733&rep=rep1&type=pdf

that runs through a basic implementation in Haskell. Although this is
academically interesting, the implementation sucks because it is written in
Haskell (half of the code is just working around lack of mutation!) and it
doesn't implement the interesting bit: the value restriction.

Is there a similar tutorial providing a walkthrough of the construction of a
type inferer for an impure language? For example, what is the inferred type
of the empty array and can that even be represented using the code from
that paper? Also, does anyone have a minimal implementation written in ML?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u

Greg Fitzgerald

unread,
Feb 24, 2010, 7:10:04 PM2/24/10
to
Hi Jon,

On Feb 24, 2010, Jon Harrop wrote:
> Is there a similar tutorial providing a walkthrough of the construction of a
> type inferer for an impure language? For example, what is the inferred type
> of the empty array and can that even be represented using the code from
> that paper? Also, does anyone have a minimal implementation written in ML?

There's an ML implementation of System F in Chapter 25 of Benjamin
Pierce's "Types and Programming Languages."

http://www.cis.upenn.edu/~bcpierce/tapl/index.html

-Greg

Jon Harrop

unread,
Feb 24, 2010, 11:06:45 PM2/24/10
to

Isn't System F also purely functional?

Ganesh Sittampalam

unread,
Feb 25, 2010, 3:00:08 AM2/25/10
to
On 24 Feb, 12:35, Jon Harrop <j...@ffconsultancy.com> wrote:
> I'd like to implement the HM type system with type inference in my language
> front-end. I once lashed together something that seemed to work but, given
> the theoretical foundation behind this, I'd like to follow some more
> rigorous guidance this time.
>
> I found an interesting draft paper "Algorithm W Step by Step":
>
> http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7733&rep=...

Another link here since citeseer can be unreliable:
http://www.grabmueller.de/martin/www/pub/AlgorithmW.en.html

> that runs through a basic implementation in Haskell. Although this is
> academically interesting, the implementation sucks because it is written in
> Haskell (half of the code is just working around lack of mutation!)

The only bits I see that could reasonably be considered "working
around lack of mutation" are the definitions of the monadic
infrastructure, which amount to three import lines and about 15-20
lines at the bottom of page 3/top of page 4, some of which would be
needed anyway to initialise/manipulate mutable state directly. That's
not "half the code".

Ganesh

Torben �gidius Mogensen

unread,
Feb 25, 2010, 4:01:13 AM2/25/10
to
Jon Harrop <j...@ffconsultancy.com> writes:


> Is there a similar tutorial providing a walkthrough of the construction of a
> type inferer for an impure language? For example, what is the inferred type
> of the empty array and can that even be represented using the code from
> that paper? Also, does anyone have a minimal implementation written in ML?

Most ML compilers are written in ML, so you could look at the source
code of these. There are no tutorials to go with them, though. My
guess is that tutorials would skip the complicated parts such as
references, arrays extensible records anyway.

The Moscow ML compiler is fairly straight-forward, so you could start
there.

Torben

Jon Harrop

unread,
Feb 25, 2010, 10:42:22 AM2/25/10
to
Torben �gidius Mogensen wrote:
> Jon Harrop <j...@ffconsultancy.com> writes:
>> Is there a similar tutorial providing a walkthrough of the construction
>> of a type inferer for an impure language? For example, what is the
>> inferred type of the empty array and can that even be represented using
>> the code from that paper? Also, does anyone have a minimal implementation
>> written in ML?
>
> Most ML compilers are written in ML, so you could look at the source
> code of these. There are no tutorials to go with them, though. My
> guess is that tutorials would skip the complicated parts such as
> references, arrays extensible records anyway.

Yes, that's exactly what I'm finding. The tutorials don't cover mutation or
even touch upon value restrictions.

> The Moscow ML compiler is fairly straight-forward, so you could start
> there.

Thanks.

0 new messages