What is wrong in my code:
insertValue file x =
if x == \"10\" then \"ok\"
else do putStrLn \"Error\"; file
You need to use return :: a -> IO a to "lift" your strings into 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 a Maybe value? Otherwise you are returning file or "ok" and your caller could never determine if there was an error when calling insertValue on a file named "ok".