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

Henning Thielemann lemming at henning-thielemann.de
Wed Jun 2 09:49:00 EDT 2010


On Wed, 2 Jun 2010, Maciej Piechotka wrote:

> 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 do not like to see the type class mechanism as a way to use common 
identifiers and symbols in as many as possible applications. Instead for 
me type classes are a way to write algorithms in a way that they can be 
used for many particular types. So far I had no algorithm that works 
equally well on integral 'div' and fractional '/'. Can you give me an 
example of an algorithm, where in one case instantiation to Integer and 
'div' is sensible and in another case instantation to Rational and '/' is 
sensible?


More information about the Haskell-Cafe mailing list