[Haskell-cafe] confusion about 'instance'....

Luke Palmer lrpalmer at gmail.com
Thu Jan 10 09:00:57 EST 2008


On Jan 10, 2008 1:36 PM, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> Hello Mark,
>
> Thursday, January 10, 2008, 4:25:20 PM, you wrote:
>
> "instance Num a => A a"
>
> > Mean the same thing as
>
> > "instance A (forall a.Num a=>a)"
>
> programmers going from OOP world always forget that classes in Haskell
> doesn't the same as classes in C++. *implementation* of this instance
> require to pass dictionary of Num class along with type. now imagine
> the following code:
>
> f :: A a => a -> a
>
> f cannot use your instance because it doesn't receive Num dictionary
> of type `a`. it is unlike OOP situation where every object carries the
> generic VMT which includes methods for every class/interface that
> object supports

I'm not sure that's a good argument.  It doesn't need a Num dictionary,
it only needs an A dictionary.  That's what it says.  You only need a Num
dictionary in order to construct an A dictionary, which seems perfectly
reasonable.

Luke


More information about the Haskell-Cafe mailing list