如何在Haskell中评估IO Bools [英] How to evaluate IO Bools in Haskell

查看:106
本文介绍了如何在Haskell中评估IO Bools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个函数,该函数需要一个IO Bool并根据这个函数做什么,但我无法弄清楚如何评估IO Bool。我试着说做了cond do {cond == True} ,但得到错误 Couldn与预期类型'b b'不匹配'a b'。有人可以指导我解决问题吗?

I'm trying to write a function that takes an IO Bool and does stuff based on what this is, but I can't figure out how to evaluate the IO Bool. I tried saying do cond and do {cond==True} but got the error Couldn't match expected type 'Bool' against inferred type 'a b'. Can someone direct me to a solution?

推荐答案

在使用之前,您需要解压/它。这里有一个例子:

You'll need to unpack/pull the bool out of IO before you can use it. Here's an example:

main = useBool trueIO

trueIO :: IO Bool
trueIO = return True

useBool :: IO Bool -> IO ()
useBool a = do
    b <- a
    putStrLn (show b)

这篇关于如何在Haskell中评估IO Bools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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