-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate away from Eq1/Ord1/Show1 #27
Comments
Please write a patch and check what happens with at least few direct dependencies (from https://packdeps.haskellers.com/reverse/data-fix, e.g. |
Does #29 solve the optimisation problem? You'd still need |
Yes, looks good. |
Done in #29 |
Continuing on haskell/core-libraries-committee#190 (comment), I propose to migrate from
to
or if you fancy
QuantifiedContraints
The motivation is that I recently migrated a codebase from a homegrown
newtype Fix
withinstance Ord (f (Fix f)) => Ord (Fix f)
todata-fix
and hit performance issues. They were a combination of several factors:I used
Data.Functor.Classes.Generic
to deriveOrd1
instance generically. It appeared thatfrom
andto
survived in Core, despite pretty aggressive optimization options. This is admittedly not a fault ofdata-fix
, but a general issue with usability ofEq1
/Ord1
/Show1
. I had to write all instances manually.class Ord1
contains onlyliftCompare
, but noliftLT
,liftLE
,liftGT
,liftGE
, so it has no access to<
,<=
,>=
,>
of the base functor. This implies that<
onFix f
also necessarily goes throughcompare
and takes a performance hit.It does not seem that
liftEq
/liftCompare
can be optimized away unless the base functorf
is completely monomorphic and everything is forced to inline. E. g.,(==)
specialised toFix (ListF Int)
looks reasonable, but(==)
forFix (ListF a)
goes throughliftEq
. The Core forlooks more reasonable to me.
I understand that the proposed change is a breaking one. It is however not very pronounced: in recent
base
we haveclass (forall a. Eq f a) => Eq1 f
, so the majority of users will not even notice. It's only if you requireEq (Fix f)
as a constraint, but useliftEq
inside, which will explode, becauseEq1 f
is no longer guaranteed. I think, however, that GHC would yell if encountersEq (Fix f)
constraint, suggesting to replace it withEq1 f
.@phadej what do you think?
The text was updated successfully, but these errors were encountered: