
On Aug 3, 2011 1:33 PM, "Patrick Browne"
instance Class Integer => SubClass Integer where moo a = foo a
Since you've just written the Class instance for Integer, the superclass context is actually irrelevant there. You may as well just write instance SubClass Integer where moo a = foo a And that goes to the point of what the difference is. In the first case, you were declaring that all SubClass instances are Class instances, and that mo defaults to foo for ALL types. In the latter case, you're defining this just for Integer. The difference is whether that default exists for other tyoes, or if its specific to Integer. -- Chris Smith

Try :t (foo 2, moo 2) On 3 Aug 2011, at 23:31, Patrick Browne wrote:
Below are examples of using the sub-class context at class level and at instance level. In this simple case they seem to give the same results In general, are there certain situations in which one or the other is preferred? Pat module CLASS where -- class and sub-class class Class a where foo :: a -> a foo a = a class Class a => SubClass a where moo :: a -> a moo a = foo a instance Class Integer where instance SubClass Integer where *CLASS> :t foo 2 foo 2 :: forall t. (Class t, Num t) => t *CLASS> :t moo 2 moo 2 :: forall t. (SubClass t, Num t) => t module INSTANCE where -- Using context at instance level -- Is class Class a where foo :: a -> a foo a = a class SubClass a where moo :: a -> a
instance Class Integer where instance Class Integer => SubClass Integer where moo a = foo a INSTANCE> :t foo 2 foo 2 :: forall t. (Class t, Num t) => t INSTANCE> :t moo 2 moo 2 :: forall t. (SubClass t, Num t) => t _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Chris Smith
-
Miguel Mitrofanov
-
Patrick Browne