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 6851815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:17:38+00:00 2026-05-27T01:17:38+00:00

This code (taken from Learn You A Haskell ): main = do putStr Hey,

  • 0

This code (taken from Learn You A Haskell):

main = do   putStr "Hey, "  
            putStr "I'm "  
            putStrLn "Andy!"  

apparently desugars to

main =        putStr "Hey, " >>=  
       (\_ -> putStr "I'm "  >>= 
       (\_ -> putStrLn "Andy!"))

Which, as I understand it can be interpretted as saying “In order to putStrLn “Andy!” I first need to putStr “I’m “, and in order to do that I first need to putStr “Hey, “;

I disagree with this interpretation, which is annoying because the compiler obviously doesn’t and leaves me feeling confused. The problem I have with it is that the lambdas ignore their arguments, during lazy evaluation isn’t this sort of thing supposed to be recognised and short-circuited?

Also, sure, the binding returns an IO action, and when that IO action falls into main it gets executed. But what’s to stop it from printing “Hey, Andy!I’m “? I suspect it’s whatever bind is doing.

Also, how does an IO action of type “IO ()” carry enough information to allow the runtime system to print “Hey, I’m Andy!”? How is that IO () different to an IO () than prints “Hello World!” or writes to a file?

Consider another, from the wikipedia page for monad:

Sugared version:

do
  putStrLn "What is your name?"
  name <- getLine
  putStrLn ("Nice to meet you, " ++ name ++ "!")

Desugared version:

putStrLn "What is your name?" >>= 
   (\_ ->
      getLine >>=
         (\name ->
            putStrLn ("Nice to meet you, " ++ name ++ "!")))

Similar story here.

I think I just need to see the definition of bind for IO and then it will be all clear. Something else that would help a lot is if someone could help me step through how the program actually gets evaluated and identify the exact moments when the side effects occur.

  • 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-27T01:17:39+00:00Added an answer on May 27, 2026 at 1:17 am

    Read the "Tackling the awkward squad" paper by Simon Peyton Jones.

    For related questions, see

    • What does "pure" mean in "pure functional language"? ,
    • Is Haskell truly pure (is any language that deals with input and output outside the system)?
    • In what sense is the IO Monad pure?
    • Haskell: actual IO monad implementation, in different language?
    • Why does Haskell not have an I Monad (for input only, unlike the IO monad)?
    • References for learning the theory behind pure functional languages such as Haskell?

    Take any such explanation including mine with a grain of salt – no hand-waving can replace a rigorous peer-reviewed paper, and the explanations are necessarily over-simplifications.

    A very rough perspective is that >>= can be seen as a list constructor:

    data IO = [Primitive] 
    

    and IO subsystem deconstructs the value of main and consumes that list. I.e. main is just a list. So you may want to take a look at the definition of Haskell entry point above main, bind is rather uninteresting.

    You can also read papers on history of haskell and look at earlier versions of IO subsystem for insight of what is going on.

    Also look at C language is purely functional satiric post by Conal Elliott.

    The definition of functional purity is non-trivial and I remember a paper elaborating on the definition, but I don’t remember the title.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code which is taken from MVC futures and attach the Attribute
I don't understand the rationale of this code, taken from javax.swing.event.EventListenerList docs: protected void
So I have this code that takes care of command acknowledgment from remote computers,
In my computer this code takes 17 seconds (1000 millions times): static void Main(string[]
Problem Hello all! I have this code which takes my jpg image loops through
Take a look at this code: public class Test { public static void main(String...
Here's my code: @interface Game : Layer // this is from cocos2d { int
This query originally came from a VB6 program accessing MS Access tables which are
Code Taken From: Bytes to Binary in C Credit: BSchlinker The following code I
I am trying to learn a few things from http://code.google.com/p/iosched/source/checkout . I wanted to

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.