Re: Let's talk about the "classic" shape hierarchy in functional programming
- From: Vincenzo Ciancia <vincenzo_yahoo_addressguard-gmane@xxxxxxxx>
- Date: Sat, 25 Jun 2005 11:18:51 GMT
Marcin 'Qrczak' Kowalczyk wrote:
>> intersect = (fun other -> match other.kind with
>> `Circle (c2,r2) ->
>> intersect_circles (center,radius) (c2,r2)
>> | _ -> generic_intersect res other);
>
> This is not extensible: if another kind of shape wants a specialized
> code for intersecting with circles, it needs to modify previously
> written code.
Hmm. Suppose you have a circle 'c' and a box 'b'. If one calls 'intersect c
b' the circle version will be called, but if one calls 'intersect b c' the
box version will be called, so my code is wrong (I already knew, I posted
it to contribute to finding a good solution), but the "box" shape can
specialize its intersection with circles. If it has the luck to be called
first!
Now the problem is that you should define "the most specific" method
someway. You could require that each shape declare on what pairs it
specializes, but what would you do if circle specializes the intersection
with boxes, and box specializes the intersection with circles? CLOS solved
in a naive but working way which I am not sure to remember (I studied it
for a couple of months 5 years ago).
I think there is no proper solution to this latter point, however a good
implementation which detects if box has specialized the intersection to
circles even if you call 'intersect circle box' should be found.
Sorry if I overlooked something obvious, of course.
Bye
Vincenzo
--
Please note that I do not read the e-mail address used in the from field but
I read vincenzo_ml at yahoo dot it
Attenzione: non leggo l'indirizzo di posta usato nel campo from, ma leggo
vincenzo_ml at yahoo dot it
.
- Follow-Ups:
- Re: Let's talk about the "classic" shape hierarchy in functional programming
- From: Joachim Durchholz
- Re: Let's talk about the "classic" shape hierarchy in functional programming
- References:
- Re: Let's talk about the "classic" shape hierarchy in functional programming
- From: Vincenzo Ciancia
- Re: Let's talk about the "classic" shape hierarchy in functional programming
- From: Marcin 'Qrczak' Kowalczyk
- Re: Let's talk about the "classic" shape hierarchy in functional programming
- Prev by Date: Re: Let's talk about the "classic" shape hierarchy in functional programming
- Next by Date: Re: Let's talk about the "classic" shape hierarchy in functional programming
- Previous by thread: Re: Let's talk about the "classic" shape hierarchy in functional programming
- Next by thread: Re: Let's talk about the "classic" shape hierarchy in functional programming
- Index(es):
Relevant Pages
|