large-records icon indicating copy to clipboard operation
large-records copied to clipboard

generic-lens and large-anon

Open deemp opened this issue 1 year ago • 1 comments

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

deemp avatar Jul 22 '23 12:07 deemp

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).

edsko avatar Jul 25 '23 06:07 edsko