You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parseTest (takeP Nothing (-1) :: Parsec Void String String) "foo" expected behavior: return the empty string, similar to Prelude.take actual behavior: fails with a message unexpected end of input.
While a negative number of tokens is clearly a non-sensical argument to that function, I'd expect either a more informative parse error along the lines of "can not take negative number of tokens" or a behavior analogous to Prelude.take where take (-1) = take 0.
The implementation of takeP for ParsecT explicitly uses EndOfInput, so this seems to be intended. Why? The Haddocks say:
It's guaranteed that if the parser succeeds, the requested number of tokens will be returned.
This is logically equivalent to:
If the requested number of tokens can not be returned, then the parser fails.
So yes, the parser honors the spec, but in a way inconsistent with its name.
The text was updated successfully, but these errors were encountered:
parseTest (takeP Nothing (-1) :: Parsec Void String String) "foo"
expected behavior: return the empty string, similar to
Prelude.take
actual behavior: fails with a message
unexpected end of input
.While a negative number of tokens is clearly a non-sensical argument to that function, I'd expect either a more informative parse error along the lines of "can not take negative number of tokens" or a behavior analogous to
Prelude.take
wheretake (-1) = take 0
.The implementation of
takeP
forParsecT
explicitly usesEndOfInput
, so this seems to be intended. Why? The Haddocks say:This is logically equivalent to:
So yes, the parser honors the spec, but in a way inconsistent with its name.
The text was updated successfully, but these errors were encountered: