POV-Ray : Newsgroups : povray.off-topic : A Haskell question... : A Haskell question... Server Time
10 Oct 2024 21:16:06 EDT (-0400)
  A Haskell question...  
From: Darren New
Date: 2 Feb 2008 22:43:22
Message: <47a5385a$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.