1

If I look at the documentation for space it suggests using void spaceChar.

However, if I actually try:

x :: Parser ()
x = void spaceChar

I get

* Couldn't match type `Token s0' with `Char'
    arising from a use of `spaceChar'
  The type variable `s0' is ambiguous
* In the first argument of `void', namely `spaceChar'
  In the expression: void spaceChar
  In an equation for `x': x = void spaceChar

I think the expression is correct, but there's something I need to do to convince the type checker. How do I get this to work?

hnefatl
  • 5,860
  • 2
  • 27
  • 49
Julian Birch
  • 2,605
  • 1
  • 21
  • 36
  • 2
    Show how you define `Parser`. Also, which version of Megaparsec are you using? – Mark Karpov Jan 08 '18 at 15:42
  • 2
    @Mark Isn't that the `Parser` from `Text.Megaparsec.String`? That being said, I cannot reproduce that issue with the `Parser` from `Text.Megaparsec.String`… – Zeta Jan 08 '18 at 15:47
  • 1
    @Zeta, Yes, I suspect this is Megaparsec 5 (according to the link), and I'm having a hard time imagining how this issue could happen... We need a full reproducing example with clarification about actual version of the library used. – Mark Karpov Jan 08 '18 at 15:50
  • megaparsec 5.3.1 – Julian Birch Jan 08 '18 at 15:55

2 Answers2

1

ghci suggests the type (Token s ~ Char, MonadParsec e s f) => f (). That one should work. Where did you get the name Parser?

Gurkenglas
  • 2,317
  • 9
  • 17
  • That gives me ``` * Could not deduce: Token s0 ~ Char arising from a use of spaceChar from the context: (Token s ~ Char, MonadParsec e s f) bound by the type signature for: x :: (Token s ~ Char, MonadParsec e s f) => f () at BLAH The type variable s0 is ambiguous * In the first argument of void, namely spaceChar In the expression: void spaceChar In an equation for `x': x = void spaceChar ``` – Julian Birch Jan 08 '18 at 15:35
0

I've tracked down the issue whilst trying to create a reproduction. The problem was a bit abstruse: I wasn't importing Control.Monad. Instead, it looks like void was being picked up somewhere else (not sure where) and this definition of void caused that error to occur. Thank you for everyone who tried to help.

Julian Birch
  • 2,605
  • 1
  • 21
  • 36