[Haskell-cafe] Re: Difference between div and /

Maciej Piechotka uzytkownik2 at gmail.com
Wed Jun 2 09:13:48 EDT 2010

On Wed, 2010-06-02 at 14:01 +1200, Richard O'Keefe wrote:
> For what applications is it "useful" to use the same symbol
> for operations obeying (or in the case of floating point
> operations, *approximating* operations obeying) distinct laws?

If the given operations do share something in common. For example * is
usually commutative. However you do use it with quaternions (Hamilton
product). You even write ij = k despite the fact that ji = -k.

I gave the code which might have work for both Integral and Fractional
but it is not possible to type it in Haskell. Although I wouldn't mind
something like:

class Num a => Divisable a where
    (./.) :: a -> a -> a

class (Real a, Enum a, Divisable a) => Integral a where
    div = (./.)

class Divisable a => Fractional a where
    (/) = (./.)

(/ and div preserve their meaning, ./. is the generalized division)

-------------- 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/20100602/eeea98e7/attachment.bin

More information about the Haskell-Cafe mailing list