putStrLn不打印到控制台 [英] putStrLn doesn't print to console
问题描述
我正在试验wxHaskell。我无法在ghci下运行应用程序,所以我必须使用应用程序来测试它。我想用println调试来测试程序。但是,似乎putStrLn在GUI中不起作用:
{ - #LANGUAGE Haskell2010# - }
模块Main其中
import Graphics.UI.WX
drawUI dc view = do
circle dc(点10 10)5 [penKind:= PenSolid ,color:= red]
putStrLn画
helloGui :: IO()
helloGui = do
f< - frame [
text: =Example,
resizeable:= False,
bgcolor:= white,
layout:= space 400 300,
on paint:= drawUI]
return( )
main :: IO()
main = do
putStrLnStarted
start helloGui
如果我注释掉开始helloGui,一切都打印好。但是,如果我将其返回,则不会打印任何内容,但会显示窗口。这里有什么不对?
这可能是输出缓冲;
显式清除:
putStrLnStarted
hFlush stdout
或者打开行缓冲:
hSetBuffering stdout LineBuffering - 甚至NoBuffering
putStrLnStarted
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"
这篇关于putStrLn不打印到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!