[PRL] annoying types ARGH! -> structure-shy

Karl Lieberherr lieber at ccs.neu.edu
Thu May 12 14:05:02 EDT 2005


Hi Matthias:

As we discussed, it is all there except the distance computations
for circles and squares. They are the same as yours.

This is an instance of the Prospector idea from Berkeley (PLDI 2005):
You have a Compound-object and you want a Simple-object. You let the
tool find the path in your class graph. 

Good ideas get reinvented many times ...

-- Karl

> -----Original Message-----
> From: Matthias Felleisen [mailto:matthias at ccs.neu.edu]
> Sent: Thursday, September 01, 2005 10:37 AM
> To: Karl Lieberherr
> Cc: 'PRL Mailing List'
> Subject: Re: [PRL] annoying types ARGH! -> structure-shy
> 
> Karl, please send out at least as much functionality as I did so
people
> can compare.
> 
> On May 12, 2005, at 10:08 AM, Karl Lieberherr wrote:
> 
> > Here is my partial program that I wrote for Matthias for the same
"free
> > variable-like problem" that Matthias solved.
> >
> > class Compound {
> > int countHits(final Point p) {
> >    Integer res = (Integer)
> >    Main.cg.traverse(this,"from Compound to Simple", new Visitor(){
> >         int containedIn;
> >         public void start() {containedIn = 0;}
> >         public void before(Simple host){if (host.contains(p))
> > containedIn++ ;};
> >         public Object getReturnValue() {return new
> > Integer(containedIn);}
> >    });
> >    return res.intValue();
> > };
> > }
> >
> > class Simple {
> > boolean contains(Point p) {
> >   return true;
> >      }
> > }
> >
> > Here is a sample input
> >
> > (
> >   ( rectangle length 7 width 9 ref 3 4
> >     circle radius 9 ref 6 7)
> >   ( circle radius 10 ref 8 3
> >     rectangle length 4 width 6 ref 5 1 )
> > )
> >
> > And the point is that the details of the data model are not
important,
> > BOTH to the program and to the test input.
> >
> > Consider this class dictionary:
> >
> > Compound = "(" <first> Shape <second> Shape ")".
> > Shape : Simple | Compound.
> > Simple : Rectangle | Circle common "ref" Point.
> > Rectangle = "rectangle" "length" <length> int "width" <width> int.
> > Circle = "circle" "radius" <radius> int.
> >
> > Point = <x> int <y> int.
> >
> > Both program and test cases also work for this class dictionary:
> >
> > Compound = "(" <elements> List(Shape) ")".
> > Shape : Simple | Compound.
> > Simple : Rectangle | Circle common "ref" Point.
> > Rectangle = "rectangle" "length" <length> int "width" <width> int.
> > Circle = "circle" "radius" <radius> int.
> >
> > Point = <x> int <y> int.
> > List(S) ~ {S}.
> >
> > Matthias solution does not have this flexibility.
> >
> > -- Karl
> >
> >
> >> -----Original Message-----
> >> From: prl-bounces at lists.ccs.neu.edu
> > [mailto:prl-bounces at lists.ccs.neu.edu]
> >> On Behalf Of Matthias Felleisen
> >> Sent: Thursday, September 01, 2005 9:43 AM
> >> To: PRL Mailing List
> >> Subject: [PRL] annoying types ARGH!
> >>
> >> I just wrote this little program for Karl:
> >>
> >>> type posn = float * float;;
> >>>
> >>> type shape =
> >>>        Circle of posn * float
> >>>      | Square of posn * float * float
> >>>      | Union of shape * shape;;
> >>>
> >>> let distance((x1,y1),(x2,y2)) =
> >>>     let dx = x1 -. x2 in
> >>>     let dy = y1 -. y2 in
> >>>       sqrt(dx *. dx +. dy *. dy)
> >>>
> >>> let rec inShape(s,p)  = match s with
> >>>     Circle(c,r) -> distance(c,p) <= r
> >>>   | Square(nw,width,height) -> false
> >>>   | Union(top,bot) -> inShape(top,p) || inShape(bot,p);;
> >>
> >> Before I finished, I had_10_ type errors, one was real. Can you
guess
> >> what went wrong?
> >>
> >> Next I had one logical error, which would have launched
anti-aircraft
> >> rockets at anything remotely on the planet. (This is an excerpt
from
> >> the Hudak-documented DoD programming contest, reformulated a in A
> >> Little Java for peaceful purposes :-)
> >>
> >> Yes, I am on record saying that I'd use OCAML if I worked in
industry,
> >> but boy this makes me reconsider this one.
> >>
> >> -- Matthias
> >>
> >>
> >> _______________________________________________
> >> PRL mailing list
> >> PRL at lists.ccs.neu.edu
> >> https://lists.ccs.neu.edu/bin/listinfo/prl
> >





More information about the PRL mailing list