Haskell UI do clause, how to print?

允我心安 提交于 2019-12-11 03:48:38

问题


This is a follow up question to this. I'm using a graphic library in Haskell called Threepenny-GUI. In this library the main function returns a UI monad object. I'm trying to execute a simple print command with no success. What is a right work around to enable printing for debugging purposes.

Code:

main :: IO ()
main = startGUI defaultConfig setup

setup :: Window -> UI ()
setup w = do

print "debug message 1 "

Error:

Couldn't match type ‘IO’ with ‘UI’
Expected type: UI ()
  Actual type: IO ()
In a stmt of a 'do' block: print "labels and values "

回答1:


Based on the types, this is a good application of liftIO. liftIO has a type MonadIO m => IO a -> m a so it can be used like this:

liftIO (print "debug message 1")

The type of that expression can be UI () since UI is an instance of MonadIO and print "debug message 1" has the type IO ().



来源:https://stackoverflow.com/questions/30988595/haskell-ui-do-clause-how-to-print

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!