Skip to content
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

generic-lens and large-anon #150

Open
deemp opened this issue Jul 22, 2023 · 1 comment
Open

generic-lens and large-anon #150

deemp opened this issue Jul 22, 2023 · 1 comment

Comments

@deemp
Copy link

deemp commented Jul 22, 2023

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
@edsko
Copy link
Collaborator

edsko commented Jul 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants