Open isovector opened 4 years ago
Using field'
instead of field
seems to work /shrug
Yes, unfortunately this is known to not work. In general, type parameters that have nominal roles are not supported well. field'
is a possible workaround. I'm now thinking it would be good to stick this into the documentation somewhere?
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, #id .~ "test"
will not work on a Refund Identity
. But it will if you add the following instance:
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 #field
syntax.
Just wanted to add a use case where I hit this. I was thinking about using generic-lens
for lsp-types
in order to avoid a lens
dependency on the types library. However, the lsp
library features a bunch of types like this:
data Method = ...
type family MessageParams (m :: Method) where ...
data Message (m :: Method) = Message {
params :: MessageParams m
...
}
Trying to use #params
to access the field gives a very similar message to the OP.
Using field'
works, and oddly it works if I split it out into separate let-bindings, i.e.
let t = msg ^. #params . #textDocument
doesn't work but
let p = msg ^. #params
t = p ^. #textDocument
does.
It would be nice if the label syntax worked, but :shrug:
For the record, built-in generic lenses (also usable via OverloadedLabels
) in optics
have full support for data families.
@arybczak I don't suppose you have any idea why it works in optics
but not here? This is annoying enough I want to fix it :joy:
@michaelpj no idea, implementation in here is quite different to what's in optics
.
The following program works!
but if you turn
Foo
into a data family, it doesn't:with the following error message:
HELP PLEASE!!!!!