-
Notifications
You must be signed in to change notification settings - Fork 11
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 example? #17
Comments
Hi @Gabriel439 , I have recently been looking into implementing Hindley-Milner via |
Ah, sorry I missed your question so long ago. Yes, you can do Hindley–Milner and I can add a worked example a bit later today. (Just have to figure out where I've stashed it :) As Brent says, you don't want to make
Of course, depending on your final goals, you may not want to bother defining your own |
My worked and (perhaps excessively) commented example can now be found here: https://byorgey.wordpress.com/2021/09/08/implementing-hindley-milner-with-the-unification-fd-library/ (source code at https://github.com/byorgey/hm-unification-fd). @wrengr , if you have time to look through it, I would be very glad to hear any suggestions for improvement! |
Ah, yes, I had it in the repo already :) test/experiments/putting/PuttingDM.hs. The code there is rather extensive yet undocumented; however, it follows the paper very closely, so it should all make sense if you read it alongside the paper. This weekend I'll move it to a more discoverable location in the repo, and see if I can't clean it up a bit. |
Ah, thanks! On a quick skim it looks kind of similar to what I ended up with (I have probably been subconsciously influenced by reading that paper long ago, and other things like it). The one part I'm not sure I understand is why the code for finding free type variables is so complicated. That makes me worried that I've done it incorrectly in my implementation. |
It doesn't seem so complicated to me? Though if I had to guess, I think you might be referring to the need to handle the Fwiw, the algorithm is as follows.
Footnote: Technically we don't need to do the |
Ah, that makes sense, thanks for the detailed explanation! |
Is it possible to implement the Hindley Milner type inference algorithm using this package's API? The reason I ask is that I made an initial attempt to do so, but ran into difficult making polymorphic types
Unifiable
.To illustrate this, usually the way the types are encoded in the HM algorithm is something like:
Now, I can make
Monotype
implementUnifiable
by doing this:… but I can't make
Polytype
implementUnifiable
(at least, not in a useful way, as far as I can tell). Is this a limitation of theunification-fd
API or am I missing something?The text was updated successfully, but these errors were encountered: