<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace">The class <span style="background-color:rgb(255,242,204)">Num</span> defines the method functions like <span style="background-color:rgb(255,242,204)">(+)</span>, <span style="background-color:rgb(255,242,204)">(-)</span>, <span style="background-color:rgb(255,242,204)">(*)</span>, <span style="background-color:rgb(255,242,204)">negate</span>, ...</div><div class="gmail_default" style="font-family:'courier new',monospace">But they are actually different concepts.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">We often meet situations that we want an addition for some type, but</div><div class="gmail_default" style="font-family:'courier new',monospace">not a multiplication. For example:</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">    <b><font color="#000000">data</font></b> <font color="#6aa84f">Vec3</font> = <font color="#bf9000">Vec3</font> <font color="#6aa84f">Float Float Float</font></div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">The additive (and subtractive) operation is obvious, but not for a</div><div class="gmail_default" style="font-family:'courier new',monospace">multiplication.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace"><font color="#999999"><i>  Note</i></font></div><div class="gmail_default" style="font-family:'courier new',monospace"><span style="background-color:rgb(255,255,255)"><br></span></div><div class="gmail_default" style="font-family:'courier new',monospace"><span style="background-color:rgb(255,255,255)">    </span><font style="background-color:rgb(255,255,255)" color="#bf9000">(*)</font><span style="background-color:rgb(255,255,255)"> :: <font color="#6aa84f">a</font> -> </span><span style="color:rgb(106,168,79)">a</span><span style="background-color:rgb(255,255,255)"> -> </span><span style="color:rgb(106,168,79)">a</span><span style="background-color:rgb(255,255,255)">   </span><font style="background-color:rgb(255,255,255)" color="#990000">-- not avaliable for a Vec3</font><br></div><div class="gmail_default" style="font-family:'courier new',monospace"><span style="background-color:rgb(255,255,255)"><br></span></div><div class="gmail_default" style="font-family:'courier new',monospace">    <font color="#bf9000">scale</font> :: <font color="#6aa84f">Float</font> -> <font color="#6aa84f">Vec3</font> -> <span style="color:rgb(106,168,79)">Vec3</span></div><div class="gmail_default" style="font-family:'courier new',monospace">    <font color="#bf9000">dot</font> :: <span style="color:rgb(106,168,79)">Vec3</span> -> <span style="color:rgb(106,168,79)">Vec3</span> -> <span style="color:rgb(106,168,79)">Float</span></div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">We cannot define a <span style="background-color:rgb(255,242,204)">(+)</span> alone for a type, so we got many different functions</div><div class="gmail_default" style="font-family:'courier new',monospace">from different libs, like <span style="background-color:rgb(255,242,204)">mappend</span>, <span style="background-color:rgb(255,242,204)">mplus</span>, <span style="background-color:rgb(255,242,204)">plus</span>, <span style="background-color:rgb(255,242,204)">(<+>)</span>, <span style="background-color:rgb(255,242,204)">(.+.)</span>, <span style="background-color:rgb(255,242,204)">(+.)</span>, which all reads</div><div class="gmail_default" style="font-family:'courier new',monospace">"plus".</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">My opinion is that the methods of <span style="background-color:rgb(255,242,204)">Num</span> should be seperated into different type</div><div class="gmail_default" style="font-family:'courier new',monospace">classes, so we don't need to invent a new symbol for a new lib.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style=""><font face="courier new, monospace">A feasible design is:</font></div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style=""><div class="gmail_default" style=""><font face="courier new, monospace">    <b>import</b> <font color="#c27ba0">Prelude</font> <b>hiding</b> ( <font color="#6aa84f">Num</font> (..), <font color="#38761d">Monoid</font> (..), sum )</font></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><font face="courier new, monospace">    <b>class</b> <font color="#3d85c6">SemiGroup</font> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> <b>where</b></font></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">(+)</font>         :: <font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace"><br></font></div><div class="gmail_default" style=""><font face="courier new, monospace">    <b>class</b> </font><span style="color:rgb(61,133,198);font-family:'courier new',monospace">SemiGroup</span><font face="courier new, monospace"> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> => <font color="#3d85c6">Monoid</font> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> </font><b style="font-family:'courier new',monospace">where</b></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">zero</font>        :: </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><span style="color:rgb(56,118,29);font-family:'courier new',monospace">    </span></div><div class="gmail_default" style=""><font face="courier new, monospace">    <b>class</b> </font><span style="color:rgb(61,133,198);font-family:'courier new',monospace">Monoid</span><font face="courier new, monospace"> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> => <font color="#3d85c6">Group</font> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> </font><b style="font-family:'courier new',monospace">where</b></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">negate</font>      :: </font><font face="courier new, monospace"><font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">(-)</font>         :: </font><font face="courier new, monospace"><font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace"><br></font></div><div class="gmail_default" style=""><font face="courier new, monospace">        x <font color="#bf9000">-</font> y    = x + negate y</font></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">negate</font> x = zero - x </font></div><div class="gmail_default" style=""><font face="courier new, monospace"><br></font></div><div class="gmail_default" style=""><font face="courier new, monospace">    </font><b style="font-family:'courier new',monospace">class</b><font face="courier new, monospace"> </font><span style="color:rgb(61,133,198);font-family:'courier new',monospace">Group</span><font face="courier new, monospace"> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> => <font color="#3d85c6">Ring</font> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> </font><b style="font-family:'courier new',monospace">where   </b><span style="font-family:'courier new',monospace"><font color="#990000">-- not sure about the name ...</font></span></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">(*)</font>         :: </font><font face="courier new, monospace"><font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><span style="color:rgb(56,118,29);font-family:'courier new',monospace">    </span></div><div class="gmail_default" style=""><font face="courier new, monospace">    </font><b style="font-family:'courier new',monospace">class</b><font face="courier new, monospace"> </font><span style="color:rgb(61,133,198);font-family:'courier new',monospace">Ring</span><font face="courier new, monospace"> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span><font face="courier new, monospace"> => <font color="#3d85c6">Num</font> a <b>where</b></font></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">abs</font>         :: </font><font face="courier new, monospace"><font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">signum</font>      :: </font><font face="courier new, monospace"><font color="#38761d">a</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace">        <font color="#bf9000">fromInteger</font> :: <font color="#38761d">Integer</font> -> </font><span style="color:rgb(56,118,29);font-family:'courier new',monospace">a</span></div><div class="gmail_default" style=""><font face="courier new, monospace"><br></font></div><div class="gmail_default" style=""><font face="courier new, monospace">    </font><span style="font-family:'courier new',monospace"><font color="#bf9000">sum</font> :: (</span><span style="font-family:'courier new',monospace">Foldable t, </span><span style="font-family:'courier new',monospace">Monoid a) => t a -> a</span></div><div class="gmail_default" style=""><span style="font-family:'courier new',monospace">    <font color="#bf9000">sum</font> = foldl' (+) zero</span></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><font face="courier new, monospace">    <font color="#990000">-- for compatibility </font></font></div><div class="gmail_default" style=""><font face="courier new, monospace">    <font color="#bf9000">mempty</font> = <font color="#000000">zero</font></font></div><div class="gmail_default" style=""><font face="courier new, monospace">    <font color="#bf9000">mappend</font> = <font color="#000000">(+)<br></font></font></div><div class="gmail_default" style=""><font face="courier new, monospace"><font color="#000000">    </font></font><span style="color:rgb(191,144,0);font-family:'courier new',monospace">mconcat</span><span style="font-family:'courier new',monospace"><font color="#000000"> = sum</font></span></div><div class="gmail_default" style=""><font face="courier new, monospace"><font color="#000000"><br></font></font></div></div></div>