I have a function (in a module) that returns IO (Maybe a) where a is an instance of the Serialize.
From my main Program I call this as follows:
msg <- fun token
print msg
and get the error
Ambiguous type variable `a0' in the constraints:
(Data.Serialize.Serialize a0) arising from a use of `foo'
at test_00.hs:13:15-19
(Show a0) arising from a use of `print' at test_00.hs:17:9-13
Probable fix: add a type signature that fixes these type variable(s)
I know exactly what the problem is and I can fix it using -XScopedTypeVariables and some changes in how I call my library function as follows:
(msg :: Maybe String) <- cwPop token
print msg
However, I would rather like to avoid the ScopedTypeVariables and wonder where it is any way that I can test if msg is member of the show class and then print it. If not do something else .
You can give a type signature to the expression on the right hand side of the
<-without extensions,(I have made the indentation so that
printandmsgaren’t arguments tofunanymore, your indentation seemed to be broken).