Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:29:34+00:00 2026-05-20T18:29:34+00:00

I am going through Write Yourself a Scheme in Haskell . Its a great

  • 0

I am going through Write Yourself a Scheme in Haskell. Its a great tutorial, but I’ve run into a wall with one of the parsing exercises:

parseNumber :: Parser LispVal
parseNumber = liftM (Number . read) $ many1 digit

Rewrite parseNumber using:

  1. Do-notation
  2. explicit sequencing with the >>= operator

I had no problems with do-notation:

parseNumber :: Parser LispVal
parseNumber = do x <- many1 digit 
                 let y = read x
                 return $ Number y

For #2 I’ve tried a bunch of variations such as:

parseNumber :: Parser LispVal
parseNumber = (many1 digit) >>= (liftM (Number . read))

but I keep running into type errors. I have two questions.

  1. Why am I getting type errors? Am I misunderstanding the monadic bind operator?
  2. Why AREN’T I getting similar type errors with my do-notation solution?

I feel like I am missing a fundamental concept regarding types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:29:35+00:00Added an answer on May 20, 2026 at 6:29 pm

    You’re attempting a non-trivial transformation from do-notation to bind notation, I recommend doing it the “trivial” way, and then making it points-free.

    Recall:

     x <- m    === m >>= \x ->
     let x = e === let x = e in
    

    Then you have:

     parseNumber = many1 digit >>= \x ->
                   let y = read x in
                   return (Number y)
    

    (I’ve removed the $ to avoid precedence problems.)

    We can then convert this into:

     parseNumber = many1 digit >>= \x -> return (Number (read x))
                 = many1 digit >>= return . Number . read
    

    Now, if you want to use liftM, you need to stop using bind, since the lifted function expects a monadic value as its argument.

     parseNumber = liftM (Number . read) (many1 digit)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going through Write Yourself a Scheme and am struck at the exercise 4
Going through the microsoft authentication tutorial listed here they have you create a master
After going through the Appendix A, C# Coding Style Conventions of the great book
Just going through the sample Scala code on Scala website, but encountered an annoying
I've been going through the screencasts here to learn how to write a table-based
I was going through some book and I decided to write my own implementation
So I'm going through Stanford's DB class , and on one of the questions
My mind seems to be going blank on this one. I have to write
We have been going through a big memory leak analysis and have found one
I've been going through a beginning Python book, and I've been trying to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.