[Haskell-cafe] Newbie Q: Deriving MyOrd from Eq problem
Bulat Ziganshin
bulat.ziganshin at gmail.com
Tue Jul 25 12:46:21 EDT 2006
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 at gmail.com
More information about the Haskell-Cafe
mailing list