> 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

Yes that is a bit misleading.  It now says:

        Probable cause: missing `Read b' in the type signature of an
expression

> 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).

Right.  The type you declared for bar says

        bar :: FORALL b. Read b => a -> b

and plainly stringBar is less general than that.

The instance at String (i.e. [Char]) is illegal in H98.


Simon

Reply via email to