[Haskell-cafe] Difference between div and /
Jonas Almström Duregård
jonas.duregard at gmail.com
Tue Jun 1 14:26:55 EDT 2010
One might expect a == (a/b)*b and other common arithmetic formulas to
hold for division?
/Jonas
On 31 May 2010 14:32, Maciej Piechotka <uzytkownik2 at gmail.com> wrote:
> 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).
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
More information about the Haskell-Cafe
mailing list