[Haskell-cafe] OOP'er with (hopefully) trivial questions.....

Jules Bean jules at jellybean.co.uk
Tue Dec 18 04:51:18 EST 2007

Miguel Mitrofanov wrote:
>> There's a third way, too, and I haven't seen anybody mention it yet
> I've noticed it, but there are some problems with this representation, 
> so I decided not to mention it. It's OK as far as we don't want 
> functions working on two areas - I don't see, how we can implement, say, 
> intersect :: Shape -> Shape -> Bool in this way. However, it's a useful 
> pattern.

The problem is no better or worse for this third way than for type classes.

class Shape a where {
   intersect :: Shape b => a -> b -> Bool

data Shape a = { intersect :: Shape b => a -> b -> Bool }

in fact, the syntax is rather similar, too! :)


More information about the Haskell-Cafe mailing list