
22 Feb
2009
22 Feb
'09
7:37 a.m.
On Sun, Feb 22, 2009 at 4:23 AM, Colin Paul Adams
parse_integer :: Parser Int parse_integer = do digits <- many1 digit let n = read digits return n
'digits' come from 'digits <- many1 digit', and 'digit' comes from Parsec itself[1] (and is the same as 'satisfy isDigit'[2,3]). I should note that it is more idiomatic to write 'parse_integer' as
import Control.Monad (liftM)
parse_integer :: Parse Int parse_integer = read `liftM` many1 digit
if you don't need signs. HTH, [1] http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parse... [2] http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/src/Text-P... [3] http://hackage.haskell.org/packages/archive/base/4.0.0.0/doc/html/Data-Char.... -- Felipe.