[Haskell-cafe] Type of divMod
twilson at csufresno.edu
Wed Sep 28 07:05:09 UTC 2016
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
Todd Wilson A smile is not an individual
Computer Science Department product; it is a co-product.
California State University, Fresno -- Thich Nhat Hanh
More information about the Haskell-Cafe