Haskell UI做子句,如何打印? [英] Haskell UI do clause, how to print?

查看:139
本文介绍了Haskell UI做子句,如何打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个。我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆