[Haskell-cafe] Difference between div and /
Maciej Piechotka
uzytkownik2 at gmail.com
Mon May 31 08:32:18 EDT 2010
I started to wonder what is the difference between div and / so they are
2 separate symbols.
div:
Take a Integral divide and round (down)
(/):
Take a Fractional divide and usually round
In some applications I would like to use any of those but it is not
possible. Is this unification taken into account while reworking numeric
classes?
I.e. why not:
class Num a => Divisable a where
(/) :: a -> a -> a
class (Real a, Enum a, Divisable a) => Integral a where
quot :: a -> a -> a
rem :: a -> a -> a
div = (/)
mod :: a -> a -> a
x `quotRem` y = (x `quot` y, x `rem y)
x `divMod` y = (x `div` y, x `mod` y)
toInteger :: a -> Integer
class Divisable a => Fractional a where
recip = (1/) :: a -> a
fromRational :: Rational -> a
(Example does not take into account other refactoring)
Regards
PS. Why is Fd/cPid etc. Integral or even Num?
What does (stdin + stderr) `mod` stdout mean (result will be stdin).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100601/8fe0bf8d/attachment.bin
More information about the Haskell-Cafe
mailing list