<br><br><div class="gmail_quote">On Mon, Nov 3, 2008 at 2:55 PM, Daniel Fischer <span dir="ltr">&lt;<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div class="Ih2E3d"><br>
&gt; class Multiplicable a b c where<br>
&gt; &nbsp; &nbsp; mult :: a -&gt; b -&gt; c<br>
<br>
</div>Use functional dependencies {-# LANGUAGE FunctionalDependencies #-},<br>
<br>
class Multiplicable a b c | a b -&gt; c where ...<br>
<br>
which states that the result type of multiplication is determined by the<br>
argument types<br>
<br>
or type families</blockquote><div><br>That&#39;s exactly what I was looking for, thank you. Now that I got that working, I&#39;ve noticed that it can be tedious making sure the arguments to sumProduct are in the correct order. Since multiplication is commutative, is there any way of automatically having the Multiplicable instances generate a &quot;flip&quot; mult?<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&gt; sumProduct :: (Addable c, Multiplicable a b c) =&gt; [a] -&gt; [b] -&gt; c<br>
<div class="Ih2E3d">
&gt; sumProduct x y = sum $ product x y<br>
&gt;<br>
&gt; weightedAverage x y = (sumProduct y x) `divide` (sum y)<br>
&gt;<br>
&gt; class Dividable a b c where<br>
&gt; &nbsp; &nbsp; divide :: c -&gt; a -&gt; b<br>
<br>
</div>FunDep here, too, but which one?</blockquote><div><br>I did class Dividable a b c | c a -&gt; b where...<br><br>Michael<br></div></div><br>