user550617
user550617

Reputation:

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' against inferred type 'a b'. Can someone direct me to a solution?

Upvotes: 1

Views: 1185

Answers (1)

Adam Wagner
Adam Wagner

Reputation: 16107

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)

Upvotes: 8

Related Questions