How to evaluate IO Bools in Haskell
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)
精彩评论