[Haskell-beginners] parsec question
David Virebayre
dav.vire+haskell at gmail.com
Mon Jul 19 04:14:14 EDT 2010
On Mon, Jul 19, 2010 at 9:41 AM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
> digitList :: Parser [Int]
> digitList = do d <- digit
> remainder <- digitList
> return $ read [d] : remainder
> <|>
> return []
I would write
digitList :: Parser [Int]
digitList = do
l <- many digit
let l' = map ( read -- read the string
. (: []) -- convert the digit from a char to a string
so I can "read" it
) l
return l'
That can be shortened to :
digitList :: Parser [Int]
digitList = map ( read.(:[])) `fmap` many digit
David.
More information about the Beginners
mailing list