On Sun, Nov 16, 2008 at 1:32 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Why is this wrong?
>
> ----
> class MyClass r where function :: r -> s
>
> data MyData u = MyData u
>
> instance MyClass (MyData v) where function (MyData a) = a
> ----
>
> GHC says that the type of the result of 'function' is both determined by
> the "rigid type" from MyClass and  the "rigid type" from MyData. But why
> can't both be the same?

As Bulat said, your type signature is equivalent to:

function :: forall r s. r -> s

whereas the result you're producing can't produce any s, but only
particular s's.  In essence, the result type is determined by the
input type.  One way to code this would be to use functional
dependencies:

class MyClass r s | r -> s where function :: r -> s
data MyData u = MyData u
instance MyClass (MyData v) v where function (MyData a) = a

 /g

-- 
I am in here
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to