-
Notifications
You must be signed in to change notification settings - Fork 54
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
Custom implementation of unification #1661
Comments
It may look like I haven't been very active recently --- and it's true I haven't had as much time to work on Swarm in general --- but in fact I've been working steadily on this. In the Once I finish this I will be able to tackle #154 which I am very excited about. Then eventually I'll get back around to #1087 . |
…1802) Closes #1661; towards #154. `unification-fd` is very powerful, and extremely fast, but it was written a long time ago and its age shows. It was not possible to incorporate it into our effects system in a nice way, necessitating the use of concrete monad transformers in the typechecking code. In addition it is impossible to customize, and we have been contemplating new type system features such as #153 and #154 that turn out to require hooking into the way the unification algorithm works (see #154 (comment) for more details). This PR thus removes the dependency on `unification-fd` and implements our own version of unification. It is not quite as fast as `unification-fd` but I consider the slowdown acceptable in order to gain e.g. recursive types. And of course there is also room to optimize it. The custom `UTerm` from `unification-fd` is replaced with the standard `Free` (free monad) construction from the `free` package, and the custom `Fix` from `unification-fd` is replaced with the one from `data-fix`. We also get rid of the `unifyCheck` function, which used to be a quick short-circuiting way to check whether two types definitely did not unify or might unify, allowing us to give better error messages more quickly. Now, the `=:=` unification operator itself just does this.
Right now we use the
unification-fd
package to implement unification of types during type checking, as described here. However, I think perhaps it's time to replace our use ofunification-fd
with our own custom implementation of unification. This would have a number of benefits:unification-fd
is quite old and it has some idiosyncracies that have been awkward to work around. For example, it insists on working in the context of a monad transformer stack that has an error transformer on top of its ownIntBindingT
transformer. If we implement our own we can integrate it with our existing effects framework instead.unification-fd
can only do pure structural unification. However, several features we are contemplating might need more custom processing:roll
orunroll
; we need to be able to solve for unification variables matched with recursive types, which means being able to unroll them as needed during unification.On the other hand there would also be some downsides:
unification-fd
is quite sophisticated and optimized; it is almost surely way faster than anything we might implement ourselves. However, I am hoping that this will not make too much of a difference as long as our new implementation is "good enough". And even if it isn't, we might be able to incorporate some optimization techniques fromunification-fd
into our own implementation.The text was updated successfully, but these errors were encountered: