
Felipe Lessa wrote:
On Dec 18, 2007 7:51 AM, Jules Bean
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