[PRL] annoying types ARGH!
Matthias Felleisen
matthias at ccs.neu.edu
Thu May 12 09:41:57 EDT 2005
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
More information about the PRL
mailing list