alt-romes / hegg

Fast equality saturation in Haskell
https://hackage.haskell.org/package/hegg
BSD 3-Clause "New" or "Revised" License
75 stars 8 forks source link

RFC : generic deriving of Ord1 and possibly more #7

Closed ocramz closed 2 years ago

ocramz commented 2 years ago

With modern GHCs, Generically1 is in base [1] and DerivingVia is available, so we can

deriving Ord1 via Genericall1 Lang.

I think Language and Analysis could also be given default instances in this way, which would enable users of hegg to just derive empty instances and GHC would do the rest.

(These are purely ergonomic improvements, which I find important but may be a matter of taste)

[1] https://hackage.haskell.org/package/base-4.17.0.0/docs/GHC-Generics.html#t:Generically1

alt-romes commented 2 years ago

I'm not sure I understood how this could be used -- an example would be good.

I attempted to derive Ord1 via Generically1 in test/Sym.hs, but wasn't able to. I'm not sure we can do that.

Secondly, Lang is defined by the user of the library, so deriving Ord1 is on their court. If this Generically1 deriving worked, we could add it to the documentation as a suggested way to fulfill the constraint.

aspiwack commented 2 years ago

I attempted to derive Ord1 via Generically1 in test/Sym.hs, but wasn't able to. I'm not sure we can do that.

You will need GHC 9.4 for that. But as far as I can tell, there are missing instances in base:

There is an instance

instance (Generic1 f, Eq1 (Rep1 f)) => Eq1 (Generically1 f)

But there are no instances of Eq1 for (:*:), (:+:), (:.:), K1, or M1. Same for Ord1. So it won't work.

@ocramz for Analysis, see also #4 .

alt-romes commented 2 years ago

So it won't work

Okay, @ocramz, I'll close this issue for now.