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

fix issue #83 and make sign function type more lenient #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/Text/Parser/Token.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,7 @@ natural = token natural'
-- or 'octal'. The number is parsed according
-- to the grammar rules in the Haskell report.
integer :: forall m. TokenParsing m => m Integer
integer = token (token (highlight Operator sgn <*> natural')) <?> "integer"
where
sgn :: m (Integer -> Integer)
sgn = negate <$ char '-'
<|> id <$ char '+'
<|> pure id
integer = token (sign <*> natural') <?> "integer"
{-# INLINE integer #-}

-- | This token parser parses a floating point value. Returns the value
Expand Down Expand Up @@ -706,7 +701,7 @@ integer' :: TokenParsing m => m Integer
integer' = int <?> "integer"
{-# INLINE integer' #-}

sign :: TokenParsing m => m (Integer -> Integer)
sign :: (TokenParsing m, Num a) => m (a -> a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the intent behind this, but it is a somewhat unforced change, as it's not required to fix #83. Moreover, the existing convention in this module is to use Integer everywhere, so I'd favor sticking to that convention.

sign = highlight Operator
$ negate <$ char '-'
<|> id <$ char '+'
Expand Down