You need to use return :: a -> IO a to "raise" your strings in an IO String :
insertValue file x = if x == "10" then return "ok" else do putStrLn "Error" return file
But are you sure you don't want to call putStrLn "ok" (instead of return "ok" ) and return Maybe? Otherwise, you return file or "ok" and your caller cannot determine if there was an error calling insertValue in a file named "ok".
source share