Skip to content

Change equational constraints on IsString (Parser a) to a ~ ()#229

Open
sol wants to merge 1 commit intohaskell:masterfrom
sol:dev
Open

Change equational constraints on IsString (Parser a) to a ~ ()#229
sol wants to merge 1 commit intohaskell:masterfrom
sol:dev

Conversation

@sol
Copy link
Member

@sol sol commented Apr 20, 2025

I think I just got this wrong when I originally implemented this (888b7d7, 0265427).

When you parse a constant string it is not really useful to inspect the parse result. For that reason I think it is justified to change the type from Parser Text to Parser ().

This doesn't make a difference for applicative-style code, but it helps with monadic code, making it -Wall sane, e.g. you can now say

parser = do
  ...
  "foo"
  ...

instead of

parser = do
  ...
  _ <- "foo"
  ...

Technically this is a breaking change, but I have a hard time to imagine non-contrived code that would break from this.

@Anteproperispomenon
Copy link

I know this is kinda old now, but I'd recommend against this. While it's very rare to see use of the form txt <- "static text", there are definitely cases of the form txt <- "text1" <|> "text2" <|> "text3". e.g.

parsePhrase :: Parser Text
parsePhrase = do
  txt1 <- "Not" <|> "Already"
  skipSpace
  txt2 <- "enough" <|> "too many"
  skipSpace
  txt3 <- "fish" <|> "batteries"
  void "."
  return (txt1 <> " " <> txt2 <> " " <> txt3 <> ".")

...unless this counts as a contrived example. I suppose a lot of the time, you'd be more likely to use
("foo" $> Foo) <|> ("bar" $> Bar). Still, it kinda feels like taking away functionality for not much gain.

If it's more efficient to return () instead of the text, I guess you could write a function version of that, called stxt (static text) or something short like that. Otherwise, it's not that much of an imposition to write _ <- "abc" or void "abc".

@sol
Copy link
Member Author

sol commented Jan 30, 2026

there are definitely cases of the form txt <- "text1" <|> "text2" <|> "text3"

Have you written code like this yourself, or where have you seen this?

I suppose a lot of the time, you'd be more likely to use ("foo" $> Foo) <|> ("bar" $> Bar).

Yes, exactly.

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 this pull request may close these issues.

2 participants