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

  • Home
  • SEARCH
  • 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 8743549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:41:56+00:00 2026-06-13T11:41:56+00:00

import Data.Char main = do c <- getChar if not $ isUpper c then

  • 0
import Data.Char

main = do 
    c <- getChar
    if not $ isUpper c
        then do putChar $ toUpper c
                main
        else putChar '\n'

Loading and executing in GHCi:

λ> :l foo.hs
Ok, modules loaded: Main.
λ> main
ñÑsSjJ44aAtTR
λ>

This consumes one character at time.

But in a terminal:

[~ %]> runhaskell foo.hs
utar,hkñm-Rjaer 
UTAR,HKÑM-
[~ %]>

it consumes one line at time.

Why does it behave differently?

  • 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-06-13T11:41:57+00:00Added an answer on June 13, 2026 at 11:41 am

    When you run a program in terminal it uses LineBuffering by default, but in ghci it is set to NoBuffering. You can read about it here. You will have to remove buffering from stdin and stdout to get the similar behavior.

    import Data.Char
    import System.IO
    
    main = do
        hSetBuffering stdin NoBuffering
        hSetBuffering stdout NoBuffering
        foo
    foo = do
        c <- getChar
        if not $ isUpper c
            then do putChar $ toUpper c
                    foo
            else putChar '\n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read a String and toUpper all the characters. import Data.Char main
capslocker.hs has following code: import Control.Monad import Data.Char main = forever $ do putStr
As in this code: import Data.Char groupsOf _ [] = [] groupsOf n xs
I'm still trying to crack this code: import Data.Char groupsOf _ [] = []
I import data from a TSV file with SQL Server 2008. null is replaced
I have to import data from an Excel file to database and to do
I need to import data from *.dmp file say mydump.dmp. What I'm doing is:
I was about to import data from a table in MySQL to SQL SErver
A user can import data into our website from a file. The data normally
I am trying to import data to an Oracle database. I have .imp and

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.