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

Constrained traversals #429

Open
adamgundry opened this issue Jun 20, 2021 · 2 comments
Open

Constrained traversals #429

adamgundry opened this issue Jun 20, 2021 · 2 comments

Comments

@adamgundry
Copy link
Member

See discussion starting from https://discord.com/channels/701454007775920128/855385315942203433/855825282833711115

type TraversalC c s t = (forall a b. c a b => p a b) -> p s t

This allows traversing structures containing multiple different types, satisfying a constraint. Pick c ~ Equals a b where class (a1 ~ a, b1 ~ b) => Equals a b a1 b1 to recover existing traversals.

Can/should we generalise optics to support this?

@phadej
Copy link
Contributor

phadej commented Nov 13, 2021

That discussion link needs login.

@phadej
Copy link
Contributor

phadej commented Nov 13, 2021

You have a typo, missing p:

type TraversalC p c s t = (forall a b. c a b => p a b) -> p s t

It would be more correct to speak about constrained optics:

type OpticC p c s t = (forall a b. c a b => p a b) -> p s t

then constrainted traversal would be

type TraversalC c s t = forall p. Traversing p => OpticC p c s t

and similarly constrained lens, prisms, setters, ...


Can/should we generalise optics to support this?

Can: probably yes.
Should: I'd rather see someone else try this first.

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