Skip to content

Documentation of optional assumes left catch #51

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

Closed
kl0tl opened this issue Oct 22, 2020 · 0 comments · Fixed by #52
Closed

Documentation of optional assumes left catch #51

kl0tl opened this issue Oct 22, 2020 · 0 comments · Fixed by #52

Comments

@kl0tl
Copy link
Member

kl0tl commented Oct 22, 2020

The documentation for optional states that

optional empty = pure Nothing
optional (pure x) = pure (Just x)

but the second equation holds only for types satisfying the left catch law (pure a <|> b = pure a), like Aff, and not those satisfying the distributivity law ((f <*> a) <|> (g <*> a) = (f <|> g) <*> a), like Array.

We should at least remove the second equation but I find both equations helpful together to explain the behaviour of optional and I think its behaviour for types satisfying distributivity instead of left catch can be surprising at first (optional [x] = [Just x, Nothing] with Array for instance), so perhaps we should document both the left catch and distributivity behaviours?

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

Successfully merging a pull request may close this issue.

1 participant