[ghc-steering-committee] GHC2021: DeriveAnyClass

Joachim Breitner mail at joachim-breitner.de
Mon Nov 30 20:56:55 UTC 2020


Hi,

I concur with Richard: DeriveAnyClass is convenient where it works, but
too implicit and too magical for my taste. It’s a cute trick, but in
general “just write an empty instance and hope for the best” isn't a
particular convincing solution to this problem.

There was a recent blog post, written tongue in cheek, about removing
type class features in Haskell … here it is:
https://www.parsonsmatt.org/2020/11/10/simplifying_deriving.html
and the gist here is: With DerivingVia we don’t need DeriveAnyClass:

   newtype Generically a = Generically a

   instance (Generic a, GToJSON (Rep a)) => ToJSON (Generically a) where
       toJSON (Generically a) = gtoJSON a

   data X = X 
       deriving stock Generic
       deriving ToJSON via Generically X

And the last line is easier to understand and safer than
DeriveAnyClass.

In light of these alternatives, I am still inclined to not give
DeriveAnyClass the seal of “harmless and uncontentious” :-)

Cheers,
Joachim

-- 
Joachim Breitner
  mail at joachim-breitner.de
  http://www.joachim-breitner.de/




More information about the ghc-steering-committee mailing list