I just found out about a new Haskell extension called DerivingVia
. It looks incredibly powerful, especially when paired with DerivingStrategies
and GeneralizedNewtypeDeriving
. It would save me from writing a lot of boilerplate in the past! For details see this great YouTube video by Tweag.
Edit (on 29 July): Matt Parsons has written a blog post on how this might become a bit overwhelming in more complicated examples and how he proposes to fix that (also related proposal). An interesting read.
Edit (on 13 Feb 2021): Just found this blog post by Hans Hoeglund which beautifuly utilises DerivingVia
in his iso-deriving package.
Edit (on 4 April 2023): Gabriella Gonzalez wrote a nice blog post explaining how DerivingStrategies
and GeneralizedNewtypeDeriving
can be used to tame deriving
.
Edit (on 02 Sep 2023): There's another nice example of the usage of this on Sam Tay's blog.
Responses (?)
JavaScript needs to be enabled to show responses. (Although, it is not necessary for posting them.)