-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow name representations other than String #39
Comments
I tried to make this change to get a rough initial idea of what the effect would be on the code base, and the main thing is that a lot of the type classes require an additional parameter (I'm not sure if it is possible to abstract this away somehow by using some kind of existential, similar to AnyName). Furthermore, I am not sure how to handle instances like |
I think this is a good idea, though I think we'll need to break the API to make it happen. Not saying that it's off the table, just that we'll need a major version bump and that I will need help to do it. Details I think it will require making -- @Alpha n a@ means @a@ is a naming-aware datatype with names constructed using type constructor @n@.
class NameLike n => Alpha (n :: * -> *) a where
... And then we'd have data AnyName n where
AnyName :: forall a . Typeable a => n a -> AnyName n And we would have instances like -- Bool works will any locally nameless representation `Name f :: * -> *` that represents free names by @f@
instance Alpha (Name f) Bool |
I've looked at it a bit more, and I've now introduced a multi-parameter type class There do seem to be some tricky things like the type signature for unbind :: (Alpha n p, Alpha n t, Fresh m) => Bind p t -> m (p, t) The issue here is that the type parameter It seems to me that there are two possible solutions to this:
I've also looked at how Moniker handles this. It seems they effectively use option 1, since their EDIT: Actually, in Rust you would use "turbofish" syntax |
The current representation of names is based on a String and a disambiguating integer.
Perhaps it would make sense to make names generic, such that other representations of the name (using Text, for instance), can be used. This would also allow things like attaching additional information to names (e.g., free variables might be tagged with their type).
I would propose a datatype like the following:
This is roughly the way I have (manually) implemented binding code in some of my own projects. I also tend to have a separate data type for free variables, which removes the need to check whether a name is a free variable in places where only free variables are expected (for example, a typing context typically does not hold any bound variables), like so:
I'm not actually that familiar with the design constraints of unbound-generics, and there might be considerations that make the use of this representation undesirable. I would be happy to hear any thoughts on this, and would also be willing to spend some time to implement this change.
The text was updated successfully, but these errors were encountered: