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

Improve Optics.Fold docs #426

Open
adamgundry opened this issue Jun 11, 2021 · 4 comments
Open

Improve Optics.Fold docs #426

adamgundry opened this issue Jun 11, 2021 · 4 comments

Comments

@adamgundry
Copy link
Member

At the moment Optics.Fold uses foldVL as the canonical introduction form, and has lots of canonical elimination forms. I think it would be clearer to use folding @[] instead for the introduction form, and toListOf for the elimination form. This makes explicit the connection between Fold s a and s -> [a].

@arybczak
Copy link
Collaborator

arybczak commented Jun 11, 2021

IMO foldVL is much easier to grok than folding 🤔 Its resemblence to traversalVL is analogous to how traverse_ and traverse differ.

@adamgundry
Copy link
Member Author

You're right that we should emphasise the relationship between traversalVL and foldVL. That's helpful if one understands traversals already. But I think that as a route to understanding folds without assuming an understanding of traversals, s -> [a] is simpler.

I'm currently working on a workshop about optics for ZuriHac, which is why I'm thinking about this. Once that is under control I'll try to make a PR with the doc changes I envision.

@phadej
Copy link
Contributor

phadej commented Jun 11, 2021

foldring with a stricter signature, i.e.

(forall b. (a -> b -> b) -> b -> s -> b) -> Fold s a

is IMHO simplest introduction form. Often quite optimal as well.

As I hint in #427, our type for foldVL is not entirely correct - and we don't discuss that in the docs:

*Optics.Core> :t foldVL traverse
foldVL traverse :: Traversable t => Fold (t a) a

works, but i'm not sure it should or shouldn't. (folding foldMap of foldring foldr would be better, wouldn't it?)

@arybczak
Copy link
Collaborator

folding foldMap of foldring foldr would be better, wouldn't it?

These provide different performance characteristics. Last time I checked foldVL traverse_ was the fastest for most standard containers.

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

3 participants