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

Splitting Ixed/At/Contains into their own package #1026

Open
endgame opened this issue Mar 9, 2023 · 2 comments
Open

Splitting Ixed/At/Contains into their own package #1026

endgame opened this issue Mar 9, 2023 · 2 comments

Comments

@endgame
Copy link
Contributor

endgame commented Mar 9, 2023

Splitting out indexed-traversable has allowed packages to provide *WithIndex instances without depending on lens and all of its transitive deps. It would be great if we could do this for Ixed/At/Contains, because sometimes packages want to provide those instances and depending on lens is regrettable. I'm thinking of monoidal-containers in particular.

While icontains and iat use the IndexedLens machinery, those can remain in lens. The classes themselves could be defined in terms of things only in base and the various containers packages.

@phadej
Copy link
Collaborator

phadej commented Mar 9, 2023

From sharing between optics and lens perspective, there isn't much to gain. Ixed in optics and lens look very different.

And that says that something is missing in the design. I don't know what.

For indexed-traversable I do use ifor_ and itraverse, and e.g. ialignWith which builds on top FunctorWithIndex; these classes are not lensy at all. But there's something not right about Ixed without lens or optics.

@endgame
Copy link
Contributor Author

endgame commented Mar 15, 2023

The peculiarity seems to come from the fact that optics is set up to be able to track the kind of optic ix actually returns. We could capture the "zero-or-one" nature with an operation like ix' :: Index m -> m -> Either m (IxValue m, IxValue m -> m). a Traversal written as an infinite sum of get/set pairs (either you get the structure back, or you get one value and a function that accepts one value, or you get two values and a function that accepts two values, or...), then this is like a "zero or one element unfolding" of that infinite sum.

But optics is able to say "ix gives you a lens if you index into a Naperian container", and this encoding doesn't.

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