<div style="font-family: 'Times New Roman'; font-size: 16px;">Hi,<br />The runtime behaviour of the two modules below *seems* to be the same.<br />Is this correct? <br />I am not trying to say "every building is a shelter", rather "anything that is a building must provide sheltering services".<br />I think that the use of sub-classes makes this explicit, but it *seems* that one gets the same results without the subclass.<br />Any clarification welcome.<br /><br />Regards,<br />Pat<br /><br />-- ========================================<br />module WithSubclass where<br />data SomeWhereToShelter = SomeWhereToShelter <br />class Shelter shelter where<br /> s :: shelter -> String<br />class Shelter building => Building building where<br /> b :: building -> String<br />class Shelter house => House house where<br /> h :: house -> String<br /><br />instance Shelter SomeWhereToShelter where<br /> s x = "Shelters afford basic sheltering" <br />instance Building SomeWhereToShelter where<br /> b x = (s x) ++ ", Buildings afford better sheltering"<br />instance House SomeWhereToShelter where<br /> h x = (s x) ++ (b x) ++ ", Houses afford even better sheltering"<br /><br /><br />-- =======================================<br />module WithoutSubclass where<br />data SomeWhereToShelter = SomeWhereToShelter <br /><br />class Shelter shelter where<br /> s :: shelter -> String<br />class Building building where<br /> b :: building -> String<br />class House house where<br /> h :: house -> String<br /><br />instance Shelter SomeWhereToShelter where<br /> s x = "Shelters afford basic sheltering" <br />instance Building SomeWhereToShelter where<br /> b x = (s x) ++ ", Buildings afford better sheltering"<br />instance House SomeWhereToShelter where<br /> h x = (s x) ++ (b x) ++ ", Houses afford even better sheltering"<br /></div>
<br clear=all> Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. <a href="http://www.dit.ie">http://www.dit.ie</a><br>
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. <a href="http://www.dit.ie">http://www.dit.ie</a>