Skip to content

Please change the Monoid instance #14

@blamario

Description

@blamario

The current Monoid instance of the Trifecta parser is too trivial to be useful:

instance Monoid (Parser a) where
mappend = (<|>)
mempty = empty

A much more useful instance would be:

instance Monoid a => Monoid (Parser a) where
mappend = liftA2 mappend
mempty = pure mempty

This instance could, in fact, be added to the parsers library. Here's a simple example of use:

decimal :: Parser String
decimal = some digit <> option "" (string "." <> some digit)

Note that the instance becomes even more useful with some additional combinators, such as moptional, concatMany, and concatSome from the incremental-parser package. But that's an optional extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions