Make Eq type class single method
Oleg Grenrus
oleg.grenrus at iki.fi
Wed Oct 20 17:11:34 UTC 2021
It might be they are not required.
In example like
{-# OPTIONS_GHC -ddump-simpl -dsuppress-all #-}
import System.Environment
import Data.Word
main :: IO ()
main = do
[x',y'] <- getArgs
let x, y :: Word
x = read x'
y = read y'
print (not (x == y))
GHC is smart enough to just swap the branches, relevant optimized core
looks like
case x_a4Tc of { W# x2_a3Wb ->
case x1_X4Ua of { W# y_a3Wf ->
case eqWord# x2_a3Wb y_a3Wf of {
__DEFAULT -> $fShowBool2;
1# -> $fShowBool4
}
}
};
where `$fShowBool*` are (probably, I haven't checked) printing True or
False.
I.e. expressions which are "case (not x) of True -> ..., False -> ..."
optimize well,
early enough. (IIRC that's the example used for case-of-case optimization).
- Oleg
On 20.10.2021 19.55, Sven Panne wrote:
> Am Mi., 20. Okt. 2021 um 18:51 Uhr schrieb Oleg Grenrus
> <oleg.grenrus at iki.fi <mailto:oleg.grenrus at iki.fi>>:
>
> [...] Also, we coudl add builtin rewrite rules, rewriting not
> (eqInt8 x y)
> to neInt8 x y if some benchmarks show that it would be beneficial.
>
>
> Hopefully such peephole optimizations are done much more generally
> further down the compilation pipeline, otherwise we will have more
> serious performance problems than the removal of (/=) from Eq. ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20211020/d61ebbb4/attachment.html>
More information about the Libraries
mailing list