[PRL] annoying types ARGH!

Jeffrey Palm jpalm at ccs.neu.edu
Thu May 12 10:54:49 EDT 2005


Matthias Felleisen wrote:
> 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 :-)

Don't you still have a logical error?  Why is this:

   Square(nw,width,height) -> false

Jeff
-- 
Jeffrey Palm --> http://www.ccs.neu.edu/home/jpalm



More information about the PRL mailing list