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

Henning Thielemann lemming at henning-thielemann.de
Wed Aug 22 05:10:32 EDT 2007

On Tue, 21 Aug 2007, Peter Verswyvelen wrote:

> 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
> operations).

> 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?

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
arbitrary way. Better don't do that. Type classes are for writing generic
functions. Define new infix operators where necessary.

More information about the Haskell-Cafe mailing list