3

这是对此的后续问题。我在 Haskell 中使用了一个名为Threepenny-GUI的图形库。在这个库中,主函数返回一个UImonad 对象。我正在尝试执行一个简单的打印命令,但没有成功。什么是启用打印以进行调试的正确解决方法。

代码:

main :: IO ()
main = startGUI defaultConfig setup

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

print "debug message 1 "

错误:

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

1 回答 1

5

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 ().

于 2015-06-22T19:58:34.143 回答