PutStrLn does not print to the console

I am experimenting with wxHaskell. I could not run the application under ghci, so I need to use the application to check it. I wanted to test the program using println debugging. However, it seems that putStrLn does not work in the GUI:

{-# LANGUAGE Haskell2010 #-}

module Main where

import Graphics.UI.WX

drawUI dc view = do 
  circle dc (point 10 10) 5 [penKind := PenSolid, color := red]
  putStrLn "painted"  

helloGui :: IO ()
helloGui = do
  f <- frame [
    text := "Example", 
    resizeable := False, 
    bgcolor := white,
    layout := space 400 300,
    on paint := drawUI]
    return ()

main :: IO ()
main = do
  putStrLn "Started"
  start helloGui

If I comment on the beginning of helloGui, everything will print well. However, if I return it, nothing will be printed, but a window will be displayed. What is wrong here?

+5
source share
1 answer

This is probably output buffering; the output is not recorded until the program exits.

Explicitly hiding:

  putStrLn "Started"
  hFlush stdout

Or enable line buffering:

  hSetBuffering stdout LineBuffering -- or even NoBuffering
  putStrLn "Started"
+13
source

All Articles