Proposal: Better power for Rational

Simon Peyton-Jones simonpj at microsoft.com
Mon Oct 4 10:47:27 EDT 2010


In general, it's an implementation matter where to put these functions, rather than a major design choice.  If one module is getting big and clumsy, then maybe splitting it into two would help.

However, as you say we need to think about integer-simple too, so we should perhaps think about adding the same new functions to the 'integer-gmp' and 'integer-simple' packages.  Then you would not need #ifdefs in GHC.Float, would you?  

s

| -----Original Message-----
| From: daniel.is.fischer at web.de [mailto:daniel.is.fischer at web.de]
| Sent: 04 October 2010 15:01
| To: Simon Peyton-Jones; libraries at haskell.org
| Subject: Re: Proposal: Better power for Rational
| 
| On Monday 04 October 2010 11:57:06, Simon Peyton-Jones wrote:
| > Henning
| >
| > | I'll try to create a patch, however I may need some assistance
| > | compiling base libraries.
| >
| > Thank you.  Creating a patch, attaching to a ticket with some rationale,
| > and submitting it to the libraries list, is the best way to push your
| > work over the hill and into the actual code base.   I'm sure others will
| > help.  If you get stuck, yell!
| >
| > Daniel Fischer is working in this patch too.
| >
| > Simon
| 
| Since I'm working on GHC.Float anyway, I'll include Henning's rounding etc.
| code too.
| 
| Speaking of GHC.Float, there are a few points where I would like some
| guidance on where to put things.
| 
| I could of course put everything in GHC.Float, but it's big already and I'd
| prefer not to clutter it up further.
| 
| For toRational, to avoid wasting time in gcd, I need an array for the
| number of trailing 0-bits in a byte. Also, since bit-fiddling of Integers
| is considerably slower than for fixed width types, I'd need to import
| GHC.IntWord64 since a Double mantissa won't fit in an Int on 32-bit
| systems. This could go into GHC.Float or into a GHC.Float.Utils module.
| 
| For fromRational, I need a fast integerLog2. For that, I need access to the
| internal representation of Integers when using integer-gmp and an
| alternative implementation for integer-simple (which would be much slower,
| but if you use integer-simple, performance probably isn't your foremost
| concern). I might need a few more odds and ends if special-casing for the
| results of toRational (whose denominator is a power of 2) proves to be a
| gain.
| 
| Putting all the auxiliary stuff in GHC.Float wrapped in #ifdefs is IMO an
| appalling idea.
| 
| integerLog2 and more generally integerLogBase are useful enough to be added
| to GHC.Integer (Int/Word is not yet available, so it'd be the '#' versions,
| where would the wrappers returning an Int or Word go?).
| If I need the stuff for special casing, my preferred solution would be to
| put it in GHC.Integer.Variant.Internals or add a small dedicated module for
| them to the package.
| 
| So what's the best place to put stuff?



More information about the Libraries mailing list