<div><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">Below are examples of using the sub-class context at class level and at instance level.</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3"> In this simple case they seem to give the same results<br />In general, are there certain situations in which one or the other is preferred? </font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">Pat</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">module CLASS where<br />-- class and sub-class<br />class Class a where<br /> foo :: a -> a<br /> foo a = a</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">class Class a => SubClass a where<br /> moo :: a -> a<br /> moo a = foo a</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">instance Class Integer where<br />instance SubClass Integer where</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">*CLASS> :t foo 2<br />foo 2 :: forall t. (Class t, Num t) => t<br />*CLASS> :t moo 2<br />moo 2 :: forall t. (SubClass t, Num t) => t</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3"></font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">module INSTANCE where<br />-- Using context at instance level<br />-- Is <br />class Class a where<br /> foo :: a -> a<br /> foo a = a</font></span></p><p class="MsoNormal" style="margin: 0in 0in 0pt"><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3">class SubClass a where<br /> moo :: a -> a</font></span></p><span lang="EN-IE" style="mso-ansi-language: en-ie"><font size="3"><p class="MsoNormal" style="margin: 0in 0in 0pt"><br />instance Class Integer where<br />instance Class Integer => SubClass Integer where <br /> moo a = foo a</p><p class="MsoNormal" style="margin: 0in 0in 0pt">INSTANCE> :t foo 2<br />foo 2 :: forall t. (Class t, Num t) => t<br />INSTANCE> :t moo 2<br />moo 2 :: forall t. (SubClass t, Num t) => t</p><p class="MsoNormal" style="margin: 0in 0in 0pt"></p></font></span></div>