large-records
large-records copied to clipboard
generic-lens and large-anon
Hi! Is it possible to use generic-lens
with large-anon
?
I want something like
import Control.Lens ((&), (*~))
import Data.Generics.Labels ()
import Data.Record.Anon
import Data.Record.Anon.Overloading
import Data.Record.Anon.Simple
magenta :: Record '[ "red" ':= Integer, "green" ':= Integer, "blue" ':= Integer]
magenta = ANON{red = 1, green = 0, blue = 1}
-- maybe plus some other constraints
reduceRed :: (RowHasField "red" r Double) => Record r -> Record r
reduceRed c = c & #red *~ 0.9
ex = reduceRed magenta
large-anon
provides a LabelOptic instance from the optics
package, which will allow you to do things like this.
If you really want to use lens
rather than optics
, then probably the easiest way is to use something like toLensVL to translate an optics
lens into a van Laarhoven lens (so you'd do something like toLensVL #red
).