[Haskell-cafe] Yet another stupid question about numeric conversion

Peter Verswyvelen bf3 at telenet.be
Wed Aug 22 08:20:32 EDT 2007

> Is still don't see why you need it. I have the feeling that you abuse Num
> and Fractional classes just for re-use of symbols like (*) and (/) in an

Maybe. It is true that I had the same feeling when first using the CG
language: when v and u are (4D) vectors, then -u, u+v and u-v make perfect
sense, but u*v, u/v, abs u, signum u, fromInteger u, sin u, etc, don't. In
CG this is just solved by applying these operators componentwise. So when
u=[u1 u2], then (abs u) = [(abs u1) (abs u2)]. Maybe not really correct in
the mathematical sense, but it works fine in practice. 

It feels silly to invent new operators and names for all of these; the code
looks weird, and every function in Num, Fractional, and Floating can be
lifted fine into this componentwise scheme. I just "invented" extra
operators (dot, cross, mul) to specify dot product, cross product,
matrix/vector and matrix/matrix multiplication etc. These clearly do not fit
in the numeric classes.

Anyway, I started from scratch again, and all is working fine now. As a
Haskell newbie, I face this a lot: it seems I'm really stuck with something,
wanting to give up on Haskell, and then next day when I start my code from
scratch, then it suddenly works fine in a much more elegant way. Maybe I
should always do that before asking silly questions here ;) And I should
checkin every version that does NOT work, so I can see what went wrong. Now
I had them same when digesting C++ templates, so it's not really related to


PS: IMHO it's also a bit problematic the way the numeric classes in Haskell
are defined. It would have been nicer if it followed mathematics a bit more,
as it seems to be done in the upcoming Sun Fortress language. This is just a
*feeling* I'm having by quickly reading the Fortress language specs, so I
might be very very wrong :)

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.484 / Virus Database: 269.12.1/965 - Release Date: 21/08/2007

More information about the Haskell-Cafe mailing list