Make {P,S}Eq less magical, don't make DefaultEq the default#458
Make {P,S}Eq less magical, don't make DefaultEq the default#458RyanGlScott merged 1 commit intomasterfrom
Conversation
goldfirere
left a comment
There was a problem hiding this comment.
Looks good.
It does strike me that we could take all of this deriving code and move it either to th-desugar or another package, perhaps th-deriving. We're deriving very routing, non-singletons-specific instances -- and even with inferred constraints! Very cool stuff that others may want to hook into.
I'm not going to run off and do this, but it does seem like a nice realignment.
Currently, the `PEq` and `SEq` classes are implemented by hand in `D.S.Prelude.Eq` due to the default implementation, `DefaultEq`. But as discussed in #457, this default isn't actually wise for most singleton types. This patch removes `DefaultEq` as the default, which allows `PEq` and `SEq` to be generated with Template Haskell, just like other classes in the `D.S.Prelude.*` module namespace. As a result, this fixes #457. This refactoring led me to discover some other unusual treatment of `PEq` and `SEq`. Namely, derived instances of `PEq` and `SEq` are very magical in that they are handled entirely outside of `D.S.Partition.partitionDecs`. But there isn't much of a good reason to do so—we can just as well generate a normal `Eq` instance, then promote and single it using the existing TH machinery. The only magical thing about deriving `Eq` is that it also produces `SDecide`/`TestEquality`/`TestCoercion` instances, but that can be done independently of `PEq` and `SEq`. This patch also refactors the treatment of `deriving Eq` to remove the special casing for `PEq` and `SEq`: * The `D.S.Promote.Eq` and `D.S.Single.Eq` modules are now gone, having been subsumed by the new `D.S.Deriving.Eq` module, which generates an instance just like `singletons` would for any other `stock`-derivable class. What remains of `D.S.Single.Eq` is now located in `D.S.Single.Decide`, which only exists to generate instances of `SDecide`, `TestEquality`, and `TestCoercion`. * `D.S.TH` had strange functions `singEqInstanceOnly` and `singEqInstancesOnly` that generated instances of `SEq`, but not `PEq`. No other `stock`-derivable class had `-Only` variants like this, and given that `singEqInstance{s}` already exist, they were practically useless. I decided to take the opportunity to remove these warts.
14380cc to
c57d53a
Compare
Almost, but there are some aspects to
FWIW, I do maintain a |
Currently, the
PEqandSEqclasses are implemented by hand inD.S.Prelude.Eqdue to the default implementation,DefaultEq. Butas discussed in #457, this default isn't actually wise for most
singleton types. This patch removes
DefaultEqas the default, whichallows
PEqandSEqto be generated with Template Haskell, justlike other classes in the
D.S.Prelude.*module namespace. As aresult, this fixes #457.
This refactoring led me to discover some other unusual treatment of
PEqandSEq. Namely, derived instances ofPEqandSEqarevery magical in that they are handled entirely outside of
D.S.Partition.partitionDecs. But there isn't much of a good reasonto do so—we can just as well generate a normal
Eqinstance, thenpromote and single it using the existing TH machinery. The only
magical thing about deriving
Eqis that it also producesSDecide/TestEquality/TestCoercioninstances, but that can bedone independently of
PEqandSEq.This patch also refactors the treatment of
deriving Eqto removethe special casing for
PEqandSEq:D.S.Promote.EqandD.S.Single.Eqmodules are now gone,having been subsumed by the new
D.S.Deriving.Eqmodule, whichgenerates an instance just like
singletonswould for any otherstock-derivable class. What remains ofD.S.Single.Eqis nowlocated in
D.S.Single.Decide, which only exists to generateinstances of
SDecide,TestEquality, andTestCoercion.D.S.THhad strange functionssingEqInstanceOnlyandsingEqInstancesOnlythat generated instances ofSEq, but notPEq. No otherstock-derivable class had-Onlyvariants likethis, and given that
singEqInstance{s}already exist, they werepractically useless. I decided to take the opportunity to remove
these warts.