开发者

How to evaluate IO Bools in Haskell

开发者 https://www.devze.com 2023-04-10 12:07 出处:网络
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

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' a开发者_运维百科gainst 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号