Hi,
The runtime behaviour of the two modules below *seems* to be the same.
Is this correct?
I am not trying to say "every building is a shelter", rather "anything that is a building must provide sheltering services".
I think that the use of sub-classes makes this explicit, but it *seems* that one gets the same results without the subclass.
Any clarification welcome.

Regards,
Pat

-- ========================================
module WithSubclass where
data SomeWhereToShelter = SomeWhereToShelter
class Shelter shelter where
 s :: shelter -> String
class Shelter building => Building building where
 b :: building -> String
class Shelter house => House house where
 h :: house -> String

instance Shelter SomeWhereToShelter where
 s x = "Shelters afford basic sheltering" 
instance Building SomeWhereToShelter where
 b x =  (s x) ++ ", Buildings afford better sheltering"
instance House SomeWhereToShelter where
 h x = (s x) ++ (b x) ++  ", Houses afford even better sheltering"


-- =======================================
module WithoutSubclass where
data SomeWhereToShelter = SomeWhereToShelter

class Shelter shelter where
 s :: shelter -> String
class Building building where
 b :: building -> String
class House house where
 h :: house -> String

instance Shelter SomeWhereToShelter where
 s x = "Shelters afford basic sheltering" 
instance Building SomeWhereToShelter where
 b x =  (s x) ++ ", Buildings afford better sheltering"
instance House SomeWhereToShelter where
 h x = (s x) ++ (b x) ++  ", Houses afford even better sheltering"

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. http://www.dit.ie
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to