-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hindley-milner type system #20
base: master
Are you sure you want to change the base?
Conversation
Implementation of an hindley-milner type system with value restriction for a strict language, impure language.
Thanks.
Did you notice that we have |
I noticed you have I feel like making the surface language bigger would only result in more boilerplate and be less self-contained, which is pretty contrary to having something educational. On substitutions ... would you prefer a big step with environments? I'm not sure it would make things simpler or clearer (the interpreter is not the interesting part anyway). I can try to add more comments when I have some free time. |
I think I know how to do this. I'd like to keep the languages nice and clean, but at the same time I don't want to reject other people's contributions just because I think their code needs to be stylistically slightly different. How about if we introdue a |
Sure, I don't mind at all. Although I wouldn't mind knowing what coding style you want. :) |
The guidelines are here. You are using The non-stylistc comment is that I would prefer an evaluation loop which carrier an environment and computes from expressions to a datatype of values, rather than one that performs explicit substitutions. This will also simplify your printing functions, as you will only have to print values (and you don't print bodies of function closures). We can do this improvement later. If you do these, I'll accept the language:
Does that sounds reasonable to you? |
Sure, that sounds perfectly reasonable. I'm not sure when I'll have time to play with this again, but I'll ping you when it's done. :) |
This add the language "hm", which is a direct implementation of an hindley milner type system for an impure ml-like language. This supports references, first class function, fixpoint and type inference of polymorphic types with value restriction. The type inference algorithm is the one presented in Oleg's article.
I was slightly unsatisfied with the fact that the language called
ml
didn't actually had an ML type system, so I added it. :)One small annoying fact of this implementation is that the operators are all prefix, instead of infix, for the simple reason that I didn't bother writing the grammar for infix operators.
In order to make the internal behavior of the typechecker more apparent, all internal ids are shown using fancy utf8 subscripts: