
Why is the type of divMod not (Integral a, Integral b) => a -> b -> (a,b)? It would seem to make sense that if b is a size-limited Integral type (like Int), then since the remainder of a division is always smaller than the divisor, it could be given the same size-limited type. I found myself wanting such instances of divMod when writing a function to convert an Integer to a list of digits in some base that is an Int: toBase :: Integer -> Int -> [Int] I can work around not having the appropriate instance of divMod by using fromIntegral to convert from an Integer to an Int, but this seems wrong. Todd Wilson A smile is not an individual Computer Science Department product; it is a co-product. California State University, Fresno -- Thich Nhat Hanh

On 09/28/2016 04:05 AM, Todd Wilson wrote:
Why is the type of divMod not
(Integral a, Integral b) => a -> b -> (a,b)?
It would seem to make sense that if b is a size-limited Integral type (like Int), then since the remainder of a division is always smaller than the divisor, it could be given the same size-limited type.
The absolute value of the remainder of a division is always smaller than the absolute value of the divisor, right? -- Similar reasoning could be transferred to mod. I don't know why it isn't as you suggested. However, I find the current way simpler and easier to understand. If someone knows why we have [divMod :: a -> a -> (a, a)], please comment on it. -- Bernardo Sulzbach http://www.mafagafogigante.org/ mafagafogigante@mafagafogigante.org
participants (2)
-
Bernardo Sulzbach
-
Todd Wilson