I'm working through "Write yourself a scheme interpreter in 48 hours" and one exercise is to write a function using do notation. This is the function:
parseNumber :: Parser LispVal
parseNumber = liftM (Number . read) $ many1 digit
I tried the following, but that didn't work:
parseNumber2 :: Parser LispVal
parseNumber2 = do digits <- many1 digit
return $ liftM $ (Number . read) digits
Never mind. I indented the code incorrectly
Once you've unpacked digits, you don't need the liftM anymore. So it's just:
return $ Number $ read digits
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With