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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:56:31+00:00 2026-05-14T08:56:31+00:00

I got a problem with IO not executing in order, even inside a do

  • 0

I got a problem with IO not executing in order, even inside a do construct.

In the following code I am just keeping track of what cards are left, where the card is a tuple of chars (one for suit and one for value) then the user is continously asked for which cards have been played. I want the putStr to be executed between each input, and not at the very end like it is now.

module Main where
main = doLoop cards
doLoop xs = do  putStr $ show xs
                s <- getChar
                n <- getChar
                doLoop $ remove (s,n) xs
suits = "SCDH"
vals = "A23456789JQK"
cards = [(s,n) | s <- suits, n <- vals]
type Card = (Char,Char)
remove :: Card -> [Card] -> [Card]
remove card xs = filter (/= card) xs
  • 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-14T08:56:32+00:00Added an answer on May 14, 2026 at 8:56 am

    absz’s answer is correct, Haskell’s buffered IO is what’s causing you trouble. Here’s one way to rewrite your doLoop to have the effect you’re looking for:

    doLoop xs = do  putStrLn $ show xs
                    input <- getLine
                    let s:n:_ = input
                    doLoop $ remove (s,n) xs
    

    The two changes: use putStrLn to append a newline and flush the output (which is probably what you want), and use getLine to grab the input a line at a time (again, probably what you want).

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

Sidebar

Related Questions

I got this problem with AVAudioRecorder not working for me, at least from what
I've got a problem I'm not sure how best to solve. I have an
I've got another problem (which might not be an issue in terms of coding
We got a problem with NUnit 2.5.3: nunit-console.exe does not return after finishing all
I've got a problem in my database - somehow changes sometimes are not being
I've got the problem that the UIAlertViewDelegate method - (void)alertViewCancel:(UIAlertView *)alertView is not called
jquery-loadmask not working properly in IE8 I got a same problem. It was issue
i got problem with my code and hopefully someone able to figure it out.
I'm implementing the in-app purchase. And I got the problem while executing the delegate
I've got a problem here with a div not being placed that way I'd

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.