[Haskell-beginners] Weighted average
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
> not desirable to have both defined automatically in a way that doesn't
> 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...
More information about the Beginners