sorry if this is a silly question but....
so I want to create a proper set of linear algebra tools to write a ray-tracer
in haskell, this includes a few types, a Point and a Vector both of which can be
represented by 3 Floats, I would like the following operations..
Vector+Vector = Vector
Point + Vector = Point
Point + Point = [Invalid should be compile time error]
Point - Point = Vector
Vector - Vector = Vector
Vector * Float = Vector
Point * Float = [Error!]
.
.
.
and so on... (if your wondering what the difference between a Vector and a Point
is, I am in homogenious coordinates so that Vectors have a 4th index that is
always 0, and Points have one that is always 1) (I will also eventually have a
Matrix class, but the basic question remains the same..)
my question is... is there any way to do this using +,-,* operators? or some
other way without creating a new operator for each valid combination?
right now i have
newtype Vector = Vector (Float,Float,Float)
newtype Point = Point (Float,Float,Float)
I would like the Vector,Point differences to be checked at CompileTime.
any help (or example code) would be apreciated... I want this to be as fast as
possible...
also on a more general question... how much slower can i expect a say raytracer
to be in haskell than C? I am experementing with new algorithms so Haskell seems
very attractive in that reguard, however speed is very important to as this is
the type of application that would run for several hours in optimized C... how
much of of hit can i expect? is it always a constant overhead or are there cases
where the Haskell runtime can cause worse overhead? thanks..
John
--
--------------------------------------------------
John Meacham http://synergy.foo.net/~john/
[EMAIL PROTECTED]
--------------------------------------------------