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

Add Alt ParseT instance #12

Open
alexbiehl opened this issue Jan 29, 2017 · 6 comments
Open

Add Alt ParseT instance #12

alexbiehl opened this issue Jan 29, 2017 · 6 comments

Comments

@alexbiehl
Copy link

I use cabal to build purescript and I found that your newest version 0.9.1.0 exports a custom (<|>) which clashes with Protolude.<|> which is a reexport from Control.Applicative. I noticed because Language.PureScript.Docs.Types failed like crazy. Of course an upper bound on aeson-better-errors helped but I think using the standard Alternative instance prevents such incompatibilities in the first place.

@hdgarrood
Copy link
Owner

Sadly we can't give <|> an Alternative instance because it wouldn't be law-abiding - there's no identity element for it.

@hdgarrood
Copy link
Owner

Sorry, I mean we can't give ParseT an Alternative instance using the current <|>.

@alexbiehl
Copy link
Author

alexbiehl commented Jan 29, 2017

Ok, I see. As a side note, some parsers use the failing parser as identity for Alternative have you considered that?
(And: I can't find the Alternative laws in base where are they written down?)

@hdgarrood
Copy link
Owner

That wouldn't be an identity unfortunately, since we need p <|> empty to be the same as p. This won't be the case if p fails, because you'll get a parser which fails with whatever message empty has, as opposed to one which fails with p's message.

Also there's no way of failing with an "empty" message right now - any failure must come with a specific reason. I think this is a good thing, as "empty" is always going to be a useless error message.

The laws are documented at https://hackage.haskell.org/package/base-4.9.1.0/docs/Control-Applicative.html

@taktoa
Copy link

taktoa commented Feb 2, 2017

I just went through the exact same process as @alexbiehl and I would like to suggest the Alt typeclass from semigroupoids. It has laws that fit the bill, decent syntax (<!> is even a pretty clever choice; ! is almost |, but not quite 😄), and semigroupoids is a popular, well-maintained library. In any case, I think exporting an alias of a popular operator like <|> is a bad idea (I always hate using ansi-wl-pprint for this very reason). Note that if you do switch to Alt, you should probably re-export the typeclass, since I don't think it's a good idea to make everyone who uses the library add a dependency.

@hdgarrood
Copy link
Owner

Alt looks ideal, I'd be happy with that.

@hdgarrood hdgarrood changed the title Consider Alternative instance for ParseT Add Alt ParseT instance Dec 9, 2018
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