
Bulat, Dmitri is not necessarily "mixing [...] class and its (default) instance". Bulat, one could suspect a reasonable use of default class methods: http://www.haskell.org/onlinereport/decls.html#overloading Indeed, Dmitri's declarations make sense as default class methods. ... except for Jared's observation: the attempt to rely on Ord. If %< in place of < was used on the RHSs, then this would really look like default methods. Ralf PS: We don't want to send people using overlapping instances more often than necessary :-)
-----Original Message----- From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- bounces@haskell.org] On Behalf Of Bulat Ziganshin Sent: Tuesday, July 25, 2006 9:46 AM To: Dmitri O.Kondratiev Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Newbie Q: Deriving MyOrd from Eq problem
Hello Dmitri,
Tuesday, July 25, 2006, 8:15:41 PM, you wrote:
class Eq a => MyOrd a where (%<=), (%>), (%>=) :: a -> a -> Bool x %<= y = (x < y || x == y) x %> y = y < x x %>= y = (y < x || x == y)
you are mixing definition of class and its (default) instance. try the following:
class Eq a => MyOrd a where (%<=), (%>), (%>=) :: a -> a -> Bool
instance Ord a => MyOrd a where x %<= y = (x < y || x == y) x %> y = y < x x %>= y = (y < x || x == y)
although i don't think it is what you want. actually Haskell don't have a good way to define default instance for some subclass, although there are some proposals how this can be addressed. you should either define exactly one instance for all "Ord"ed types or duplicate this trivial definition in every instance. in GHC you also has an option to use "overlapping" instances but this can work only if all your other "instance" definitions don't use deriving from typeclasses. i.e. the following is prohibited:
class Eq a => MyOrd a where ... instance Ord a => MyOrd a where ... instance SomeClass a => MyOrd a where ...
and even if you will be accurate, i'm not sure that "overlapping" will work properly
ps: you can ask me in Russian via private mail
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe