[Haskell-cafe] implementing a class using superclasses?
Mark McConnell
mmcconnell17704 at yahoo.com
Fri Mar 28 17:46:10 UTC 2025
Thank you to everyone who replied. The thing I was misunderstanding was, to quote Jade, "This attempts to define `Ord a` in general, for *every* type `a` at once. The `Lex2 a` constraint is only checked *after* the compiler has decided this is the instance to use."
I appreciate seeing how a Proxy constructor, or DerivingVia, would solve the problem. However, I decided just to document carefully what I was doing.
On Wednesday, March 26, 2025 at 06:14:00 PM EDT, Jade Hagborg <jhagborg at quasicoherent.solutions> wrote:
On Wed, 2025-03-26 at 18:08 -0400, Jade Hagborg via Haskell-Cafe wrote:
> instance (Primary a, Secondary a) => Ord (Lex2 a) where
> compare (MkLex2 x) (MkLex2 y) = comp1 x y <> comp2 x y
My bad (copy-paste error), should be
instance (Primary a, Secondary a) => Ord (UsePrimaryAndSecondary a) where
compare (MkUsePrimaryAndSecondary x)
(MkUsePrimaryAndSecondary y) = comp1 x y <> comp2 x y
Sorry if that caused confusion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20250328/a4403653/attachment.html>
More information about the Haskell-Cafe
mailing list