|
|
How would you write this in Haskell?
struct Point {int x; int y;}
distance = sqrt(p.x*p.x + p.y*p.y);
Oh, right, Andrew doesn't know any C-like languages. Hmmm...
A "point" structure with an X and a Y element, and a distance function
that takes a point and calculates its distance from the origin.
Then, is it possible to add a Z element to the "Point" type without
having to rewrite the "distance" part? (Sure, it'll give the wrong
answer, but that's the point I'm trying to make with someone elsewhere
claiming strong typing avoids this sort of error.)
--
Darren New / San Diego, CA, USA (PST)
On what day did God create the body thetans?
Post a reply to this message
|
|