在Haskell中运行Gloss代码时发布消息
Haskell playIO具有以下类型:在Haskell中运行Gloss代码时发布消息,haskell,gloss,Haskell,Gloss,Haskell playIO具有以下类型: playIO:: Display -> Color background color -> Int -> world --initial world -> (world -> IO Picture) -- function to change world into a picture -> (Event -> world -> IO world) --event han
playIO:: Display
-> Color background color
-> Int
-> world --initial world
-> (world -> IO Picture) -- function to change world into a picture
-> (Event -> world -> IO world) --event handler function
-> (Float -> world -> IO world) -- The function to update the world after the given time
-> IO ()
一旦您在
main
内部调用playIO
,它就会持续运行,更新由world
建模的GUI。如果在处理事件的代码(请参阅代码注释)或更新世界的函数中发生了某些事情,并且您希望输出一条消息(不一定是错误),您会使用什么方法来不违反类型?您是否需要中断功能playIO
来显示我的信息?如果是这样,您将如何做到这一点 如果希望(比如)基于事件发出消息,则将该操作放入事件处理程序中。例如:
main :: IO ()
main = playIO black 100 world0 renderWorld handleEvent updateWorld
handleEvent evt w =
do print event -- Right here, you are emitting a message!
updateWorldWithEvent evt w
putStrLn "I have updated the world, now time for breakfast."
请记住,
handleEvent
操作可能会非常频繁地发生,因此请相应地选择输出。如果希望(比如)基于事件发出消息,请将该操作放入事件处理程序中。例如:
main :: IO ()
main = playIO black 100 world0 renderWorld handleEvent updateWorld
handleEvent evt w =
do print event -- Right here, you are emitting a message!
updateWorldWithEvent evt w
putStrLn "I have updated the world, now time for breakfast."
请记住,handleEvent
操作可能会频繁发生,因此请相应地选择输出