-
Notifications
You must be signed in to change notification settings - Fork 108
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
No support for polymorphism over record fields #258
Comments
Yeah I thought about it some time ago, and concluded that I don't see an easy fix right now, so I moved on. cc @danieldjohnson |
Yeah, this seems hard to do right now. I think that doing this properly would require something like type families / associated types / typeclass functional dependencies, so that you could unpack a record in a generic way without knowing its fields in advance. |
FWIW type families already work, because types are values just like any other and you can store them in typeclasses:
|
Well, they sort of work, in that you can write them down. But type inference can't reduce through them so you can't actually do anything interesting with them:
|
Fair enough, but I don't think that this is a fundamental difficulty. We should just make the reduction more powerful. |
I think it's a bit more fundamental than that, since this also violates a bunch of our internal assumptions:
I think each of these could be solved or worked around but the solution doesn't seem straightforward to me. (But I agree that this is something we should support!) |
I too like the idea of making type inference more powerful, but would that allow a solution to the record instances problem? I don't see how the necessary type families could be written without being able to refer to the names of fields. |
Not on its own, but the solution I imagined to the record problem involves type families. I was thinking something like Haskell's
and then the compiler would automatically solve something like
I suppose that this isn't strictly necessary to write typeclasses for records either, we could have the generic thing happen in the compiler itself whenever it tries to solve for an instance of a record, or something. (edit: although I'm not sure that actually works, because then the compiler has to figure out how to transform an instance for |
I was wondering if we could get away with something like
and having the compiler solve
because we don't know what equality constraints we need to solve ( |
@danieldjohnson Wouldn't your last proposal work if you parametrized |
About your earlier arguments about |
I don't think that quite works, because the "caller" is supposed to bind all of the arguments to the typeclass ADT. If we had something like
then in order to solve Regarding |
My simplex demo needs an
Eq
instance for a particular record type. I managed to make one by hand, but is it possible in the current codebase to make a generic constructor ofEq
or other typeclasses for records?For example, here's the instance for
Eq
for pairs:I started trying to write an analogous one for records, but because I can't refer to the names of the fields explicitly (or somehow quantify over them), I think it's impossible.
The text was updated successfully, but these errors were encountered: