Skip to content

Problematic IsString instance #515

Open
@j-mie6

Description

@j-mie6

Megaparsec defines an instance:

instance (a ~ Token s, IsString a, Eq a, Stream s, Ord e) => IsString (ParsecT e s m a)

Which allows for convenient syntax for parsing string symbols in a parser. However, the existence of this instance means that it is not possible to define a specialised instance for use with lexing logic (see this paper, page 8, section 3.3) without resorting to newtype hackery. This is arguably a more useful instance to have, because it can actually be used to clean up the logic of a completed parser.

Obviously, the issue here is that the instance is given in the same module as ParsecT's definition (as to not orphan it), but I would suggest actually orphaning it in a module where it is the only thing inside. That way, users can opt into this (indeed very sensible) default, and remove the import when they want to define their own specialised version. If orphaning really is to be avoided, I'd instead just recommend removing it.

In either case, this is a backwards incompatible change.

Keen to know your thoughts!

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