Re: Let's talk about the "classic" shape hierarchy in functional programming



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
.



Relevant Pages

  • Re: Holiday trip notes: TX etc.
    ... intersection with K-26 in Galena. ... meat cleaver in Oklahoma; ... straggler OK 51 circles in downtown Tulsa, and some circle 66 signs on I-44 ... On IH40 east of US69 this was unchanged; this was the case in this ...
    (misc.transport.road)
  • Re: Distance between centers of two intersecting circles that have
    ... David W. Cantrell wrote: ... want the area of the their intersection to be A (i.e. the lens is ... What is the distance d between the centers of the two circles to ...
    (sci.math)
  • Re: Oblique torus slice: intersecting circles
    ... The intersection of the torus with a plane at distance z above the XY ... the two circles that Jim Ferry asked about are on a certain plane. ...
    (sci.math)
  • Re: circle intersection help
    ... John, if my understanding of Bala's statement is correct, he isn't looking for a common intersection of the four circles, but rather the intersection of four disks, which is a different matter. ... I'll call it a circugon, ...
    (comp.soft-sys.matlab)
  • Re: cutting circles
    ... nzlstar at yahoo dot com ... I want to cut circles -- not partial circles to sew together but actual ...
    (rec.crafts.textiles.quilting)