[Haskell-cafe] Type question in instance of a class
Bulat Ziganshin
bulat.ziganshin at gmail.com
Sun Nov 16 16:49:01 EST 2008
Hello Maurício,
Monday, November 17, 2008, 12:32:11 AM, you wrote:
> class MyClass r where function :: r -> s
this tells that f may return value of any type requested at the call
site, i.e. one can write
main = do print (f (Mydata 1) :: String)
print (f (Mydata 1) :: [Bool])
print (f (Mydata 1) :: Either Double Float)
> instance MyClass (MyData v) where function (MyData a) = a
this definition can return value of only one type, so it can't serve
all the calls i mentioned above
> 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?
are you OOPer? :)
ps: GHC error messages should be fired :)
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list