A way to match RULES only for literals
In GHC/Enum
we have
{-# RULES
"enumDeltaToInteger1" [0] forall c n x . enumDeltaToIntegerFB c n x 1 = up_fb c n x 1
#-}
-- This rule ensures that in the common case (delta = 1), we do not do the check here,
-- and also that we have the chance to inline up_fb, which would allow the constructor to be
-- inlined and good things to happen.
-- We do not do it for Int this way because hand-tuned code already exists, and
-- the special case varies more from the general case, due to the issue of overflows.
This rule would be useful for all literals, not just for 1
.
I remember a discussion that such a rule would be more useful if we had a way to specify that, for example (random syntax).
{-# RULES
"enumDeltaToInteger1" [0] forall c n x d . isLiteral d => enumDeltaToIntegerFB c n x d = up_fb c n x d
#-}
I’m reporting this now to be able to link to it from #9136 (closed), where this feature might also help.