[PRL] annoying types ARGH!

Matthias Felleisen matthias at ccs.neu.edu
Thu May 12 11:22:26 EDT 2005


On May 12, 2005, at 10:54 AM, Jeffrey Palm wrote:

> 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

I was too lazy to finish. -- Matthias




More information about the PRL mailing list