Skip to content

Documentation of optional assumes left catch #51

Closed
@kl0tl

Description

@kl0tl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions