divRem by `-' performance

Albert Y. C. Lai trebla at vex.net
Thu Oct 18 19:54:45 CEST 2012

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.

More information about the Glasgow-haskell-users mailing list