How to evaluate IO Bools in Haskell

心已入冬 提交于 2019-12-11 07:13:01

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/7618092/how-to-evaluate-io-bools-in-haskell

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