I am trying to do a little error handling when opening a file, to be sure that the file exists/is readable. Here's my attempt :
init struct = do
str <- try $ readFile (filePath struct)
case str of
Left exception -> print exception
Right content -> execute content struct
(Struct is a data structure where I keep my file path and other variables). I get this error:
Ambiguous type variable ‘a0’ arising from a use of ‘try’ prevents the constraint ‘(Exception a0)’ from being solved. Probable fix: use a type annotation to specify what ‘a0’ should be.
But I just don't understand how to fix it.