[Haskell-beginners] Weighted average

Michael Snoyman michael at snoyman.com
Tue Nov 4 10:22:11 EST 2008

On Mon, Nov 3, 2008 at 3:53 PM, Daniel Fischer <daniel.is.fischer at web.de>wrote:

> Am Dienstag, 4. November 2008 00:26 schrieb Michael Snoyman:
> Beware! Multiplication is usually not commutative, think about matrices. If
> (a `mult` b) and (b `mult` a) are both defined (need not be if they have
> different types), the products may have different types, so in general it
> is
> not desirable to have both defined automatically in a way that doesn't
> force
> you to supply the arguments in the correct order.
> In your case, you could provide
> instance Multiplicable MilesPerGallon Gallon Mile where
>        mult = flip mult
> -- or write the implementation out
> and it should work whichever order the arguments are passed.

Good point. Thanks for all the help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081104/994dd9eb/attachment.htm

More information about the Beginners mailing list