[Haskell-cafe] Re: default for quotRem in terms of divMod?

Isaac Dupree isaacdupree at charter.net
Sat Aug 11 17:53:50 EDT 2007

Henning Thielemann wrote:
> Btw. is there any application, where 'quot' and 'rem' are needed? All
> occurrences of 'quot' and 'rem' I found in code so far were actually wrong
> and should have been 'div' and 'mod'.
> http://www.haskell.org/haskellwiki/Things_to_avoid#Forget_about_quot_and_rem

Yes, my implementation of Integer in terms of lists of Int, deliberately 
uses the symmetry of quotRem in order to store negative numbers as the 
negation of all elements of the positive number, and be able to 
virtually ignore the signs most of the time.  (Also because quotRem is 
usually faster, I figured it made sense to use that technique.)  (It 
doesn't make any difference on numbers that cannot be negative, also.) 
Everywhere else I remember when coding, div/mod were the correct ones to 
use (even back when I was coding in C, I wished I had that rounding 
behavior some time).

I do think that if you almost always want to _use_ div and mod, you 
should be able to just define div and mod too (not quot and rem) -- one 
reason I brought up the issue :)


More information about the Haskell-Cafe mailing list