Re: Make Eq type class single method
Joachim Breitner <[email protected]> Wed, 20 Oct 2021 17:25:22 +0200
| Newsgroups | gmane.comp.lang.haskell.libraries |
|---|---|
| Message-ID | <38243b480069a483b59a51e242e391a1c85c8201.camel@joachim-breitner.de> |
Hi, Am Mittwoch, dem 20.10.2021 um 16:08 +0100 schrieb Tom Ellis: > Since (/=) is an Eq class method it can be implemented on (Int, Int) > as > > (x1, x2) /= (y1, y2) = (x1 /= y1) || (x2 /= y2) > > If it were not a class method it would have to be implemented as, > after inlining > > (x1, x2) /= (y1, y2) = not ((x1 == y1) && (x2 == y2)) > > Might not the latter be less efficient, because of the extra `not`? maybe. I think I’ll simply try it out, and see if for example GHC itself speeds up if (/=) is not a class method. Note that if the inner Eq is using the default implementation, then there will be _two_ not there. I’d expect that not will quickly inline, and the cost of an inlined not might be small compared to the cost of projecting (/=) out of the class dictionary (in polymorphic code). And in other cases, the (/=) might inline and the not might be fused with the surrounding code via case- of-case. Cheers, Joachim -- Joachim Breitner [email protected] http://www.joachim-breitner.de/ _______________________________________________ Libraries mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries