Haskell UI做子句,如何打印? [英] Haskell UI do clause, how to print?
问题描述
这是这个。我在Haskell中使用了一个名为 Threepenny-GUI 的图形库。在这个库中,主函数返回一个 UI
monad对象。我试图执行一个简单的打印命令,但没有成功。代码:
<$>
$ b代码:
c $ c> main :: IO()
main = startGUI defaultConfig setup
setup :: Window - > UI()
setup w = do
printdebug message 1
错误:
无法将'IO'与'UI'匹配
预期类型:UI ()
实际类型:IO()
在do块的标题中:printlabels and values
基于类型,这是 liftIO
。 liftIO
有一个类型 MonadIO m => IO a - >
$ b
liftIO(printdebug message 1)
表达式的类型可以是 UI()
既然 UI
是 MonadIO
和 printdebug message 1的一个实例
的类型为 IO()
。
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 "
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 ()
.
这篇关于Haskell UI做子句,如何打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!