divRem by `-' performance

Serge D. Mechveliani mechvel at botik.ru
Thu Oct 18 21:10:39 CEST 2012

On Thu, Oct 18, 2012 at 01:54:45PM -0400, Albert Y. C. Lai wrote:
> On 12-10-18 05:24 AM, Serge D. Mechveliani wrote:
>> And concerning this example: I am not even sure now that it worths to
>> setting  $!  there.
>> Because I deliberately program  qRem  as returning a pair  (quot, rem),
>> and do not program a separate function for  rem.  And to obtain  rem,
>> one applies   snd (qRem n m),  and due to laziness,  quot  does not
>> spend the cost. I do not know, may be, using $! may damage this style.
> snd (quot, rem) does not spend the arithmetic cost of quot, but spends  
> the memory cost of quot. Memory cost is not just occupation of memory,  
> but also writing of memory and computing of addresses, which is not  
> exactly cheaper than arithmetic.

But in this example of  qRem  the time is almost so as if  quot  was
not computed. 
Probably, the coefficient of this expense is small.

On the other hand, an extra memory occupation also often causes slowing 
down of all the environment program, because this occupation approaches 
garbage collection.

I wonder whether it worths to return some strictness annotations. 


More information about the Glasgow-haskell-users mailing list