-
-
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
GetField doesn't work with data families #96
Comments
Using |
Yes, unfortunately this is known to not work. In general, type parameters that have nominal roles are not supported well. |
You can solve this on a case by case basis if you don't actually want polymorphic updates. (And.. maybe even if you do?) Let's say you have: data RefundT f = Refund { id :: B.C f String, ... } Now, import qualified Data.Generics.Labels as GL
import qualified Data.Generics.Product.Fields as GL
instance
{-# OVERLAPPING #-}
(GL.HasField' name (RefundT f) a, f ~ g, a ~ b) =>
GL.HasField name (RefundT f) (RefundT g) a b
where
field = GL.field' @name This is only if you want to use the |
Unfortunately symbols didn't work because of kcsongor/generic-lens#96. Had to revert to field' has someome suggests on the issue.
Just wanted to add a use case where I hit this. I was thinking about using
Trying to use Using
doesn't work but
does. It would be nice if the label syntax worked, but 🤷 |
For the record, built-in generic lenses (also usable via |
@arybczak I don't suppose you have any idea why it works in |
@michaelpj no idea, implementation in here is quite different to what's in |
This adopts the approach discussed here: #465 (comment) That is: - We export normal, non-prefixed record selectors (still using `DuplicateRecordFields`, of course). - Users who want lenses can use `generic-lens`; `lsp` and `lsp-test` do this. - It's sensible for `lsp-types` to define some useful lenses that aren't derived from fields; these go in a `lsp-types-lens` component. I think the result is... fine? kcsongor/generic-lens#96 is a pain in some cases, but by and large using the generic lenses is quite nice. I also tried to just use `OverloadedRecordDot` instead of lenses where I could, since we now support 9.2 as our earliest version. I couldn't quite get rid of `lens` in `lsp`, it's too useful. I did get rid of it entirely in `lsp-types`, which was quite painful in at least one place. This would obviously be a huge breaking change, but I think it's the right direction.
The following program works!
but if you turn
Foo
into a data family, it doesn't:with the following error message:
HELP PLEASE!!!!!
The text was updated successfully, but these errors were encountered: