Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do write this in do notation?

Tags:

haskell

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

like image 873
Luke Avatar asked Jun 20 '26 10:06

Luke


1 Answers

Once you've unpacked digits, you don't need the liftM anymore. So it's just:

return $ Number $ read digits
like image 180
sepp2k Avatar answered Jun 23 '26 10:06

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!