I am experimenting with wxHaskell. I wasn't able to run the app under ghci, so I have to use application to test it. I wanted to test the program with println debugging. However, it seems that putStrLn doesn't work in 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 out start helloGui, everything is printed well. However, if I return it, nothing is printed but the window is displayed. What's wrong here?
This is probably output buffering; the output is not written until the program exits.
Either flush explicitly:
putStrLn "Started"
hFlush stdout
Or turn on line buffering:
hSetBuffering stdout LineBuffering -- or even NoBuffering
putStrLn "Started"
来源:https://stackoverflow.com/questions/12435794/putstrln-doesnt-print-to-console