[Haskell-cafe] OOP'er with (hopefully) trivial questions.....
Jules Bean
jules at jellybean.co.uk
Tue Dec 18 07:30:43 EST 2007
Felipe Lessa wrote:
> On Dec 18, 2007 7:51 AM, Jules Bean <jules at jellybean.co.uk> wrote:
>> class Shape a where {
>> intersect :: Shape b => a -> b -> Bool
>> }
>
> Shouldn't this be
>
> class Shape a where
> ....whatever....
>
> class (Shape a, Shape b) => Intersectable a b where
> intersect :: a -> b -> Bool
>
> With your definition I don't see how you could make it work, as you
> would have to write a function that takes care of this shape
> intersecting with any other shape, but this is exactly the problem the
> classes should solve!
Yes, that's a better solution, certainly. MPTCs are not haskell though
:P I'm half joking, but there are solutions which don't involve
non-standard extensions even ones as popular as MPTCs.
I didn't really think mine was particularly useful, just pointing out
the design space, and in particular the precise parallel between the
classes approach and the explicit dictionary approach.
Jules
More information about the Haskell-Cafe
mailing list