[Haskell-cafe] Yet another stupid question about numeric
bf3 at telenet.be
Tue Aug 21 14:40:05 EDT 2007
Yes indeed, I realized that. I oversimplified my question. I'm basically
trying to model 4D CG/HLSL operations (pixel/vertex shaders) in Haskell.
I tried realToFrac, but that did not work. Then I tried splitting the
instances into Fractional and Integral, but I kept getting errors. Maybe
because I also made the Vector datatype an instance of Num, Fractional, etc,
which was needed to model the CG/HLSL piecewise operations (so
multiplication of two vectors is done piecewise by default in the CG model;
one has special dot, cross, and mul operations for performing the other
Anyway, although I got something working when I enabled many GHC extensions,
I dropped it for now. I notice that a lot of Haskell code uses type
annotations (e.g. in HOpenGL), so I guess that's the price one has to pay.
It would be nice if one could have a full predicate in the constraints
section of a type class, like
class ((Num a) && not (Vector4D a)) => ...
But I guess this indicates bad design?
lennart.augustsson at gmail.com wrote:
How can you hope to convert an arbitrary Num to a Float?
Num contains things like complex numbers that don't have any reasonable
translation to a Float.
But anyway, realToFrac is a good conversion function.
More information about the Haskell-Cafe