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

2007-08-22 Thread Henning Thielemann

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.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-08-21 Thread Lennart Augustsson
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.

  -- Lennart

On 8/21/07, Peter Verswyvelen [EMAIL PROTECTED] wrote:

 Does a general approach exist to convert any non-constant (Num a) to a
 Float? Not using type annotation of course.

 Now I wrote a Convert class that has a toFloat function which I
 instantiate
 for all different numeric types, but as all these toFloat/toInt functions
 disappeared a long time ago from Haskell, it feels like a bad idea to
 reintroduce them locally in my code...

 Thanks (again!)
 Peter Verswyvelen


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-08-21 Thread Henk-Jan van Tuyl
On Tue, 21 Aug 2007 18:53:43 +0200, Peter Verswyvelen [EMAIL PROTECTED]  
wrote:



Does a general approach exist to convert any non-constant (Num a) to a
Float? Not using type annotation of course.



Instances of class Integral (Int and Integer) can be converted with  
fromIntegral.


--
Met vriendelijke groet,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2007-08-21 Thread Peter Verswyvelen
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).

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? 

Thanks,
Peter


[EMAIL PROTECTED] 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.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe