Thanks! I'll definitely consider your library in the future, but for now, as we can see, there's no necessity in rewriting cFloatConv at all - {-# INLINE #-} suffices :)

On Thu, Nov 3, 2011 at 3:30 AM, wren ng thornton <> wrote:
On 11/2/11 7:14 AM, Eugene Kirpichov wrote:
I rewrote cFloatConv like this:

import GHC.Float
class (RealFloat a, RealFloat b) =>  CFloatConv a b where
  cFloatConv :: a ->  b
  cFloatConv = realToFrac

instance CFloatConv Double Double where cFloatConv = id
instance CFloatConv Double CDouble
instance CFloatConv CDouble Double
instance CFloatConv Float Float where cFloatConv = id
instance CFloatConv Float Double where cFloatConv = float2Double
instance CFloatConv Double Float where cFloatConv = double2Float

If you're going the MPTC route, I suggest you use logfloat:Data.Number.RealToFrac[1]. I don't have the CDouble and CFloat instances, but I could add them. The instances themselves are only moderately more clever than yours ---namely using CPP for portability to non-GHC compilers--- but I think it's good for people to rally around one implementation of the solution instead of having a bunch of copies of the same thing, each poorly maintained because of the distributedness.


Live well,

Haskell-Cafe mailing list

Eugene Kirpichov
Principal Engineer, Mirantis Inc.