Hi!
\begin{code}
module Test where
class Show a => Foo a where
bar :: Read b => a -> b
bar x = read (show x) :: b
\end{code}
yields:
----
Test.hs:5:
Could not deduce `Read b' (arising from use of `read' at test.hs:5)
from the context: ()
Probable cause: missing `Read b' in tcPolyExpr
In an expression with expected type: forall b1. b1
In an expression with a type signature:
read (show x) :: forall b. b
Compilation had errors
----
tcPolyExtr? The error message is at least a bit misleading, isn't it?
:-)
BTW: What I intended to do boils down to:
\begin{code}
class Show a => Foo a where
bar :: Read b => a -> b
bar x = let r = stringBar (show x)
in read r
instance Foo String where
bar x = stringBar x
stringBar :: String -> String
stringBar = id
\end{code}
which gives an error, because b cannot be unified with String (correct).
I had to work around this, using
\begin{code}
instance Foo String where
bar x = let r = stringBar x
in read ('"':r ++ "\"")
\end{code}
but that's ugly... is there a better way to achieve the same?
Cheers,
Michael
--
W*ndoze NT is faster... CRASHING!