summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBaldur Blöndal <baldurpet@gmail.com>2021-05-11 22:07:38 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-08-02 04:12:04 -0400
commita4ca6caaa2f61d1ef62db824dd2116b753cf24ee (patch)
treed71fbe273b5e7297a04e91b2d3bdac4d11555f7b /docs
parentb4d39adbb5884c764c6c11b2614a340c78cc078e (diff)
downloadhaskell-a4ca6caaa2f61d1ef62db824dd2116b753cf24ee.tar.gz
Add Generically (generic Semigroup, Monoid instances) and Generically1 (generic Functor, Applicative, Alternative, Eq1, Ord1 instances) to GHC.Generics.
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/exts/generics.rst31
1 files changed, 26 insertions, 5 deletions
diff --git a/docs/users_guide/exts/generics.rst b/docs/users_guide/exts/generics.rst
index 4299e2ccbf..d32fa246bb 100644
--- a/docs/users_guide/exts/generics.rst
+++ b/docs/users_guide/exts/generics.rst
@@ -3,10 +3,32 @@
Generic programming
===================
-Using a combination of :extension:`DeriveGeneric`,
-:extension:`DefaultSignatures`, and :extension:`DeriveAnyClass`, you can
-easily do datatype-generic programming using the :base-ref:`GHC.Generics.`
-framework. This section gives a very brief overview of how to do it.
+There are a few ways to do datatype-generic programming using the
+:base-ref:`GHC.Generics.` framework. One is making use of the
+``Generically`` and ``Generically1`` wrappers from ``GHC.Generics``,
+instances can be derived via them using :extension:`DerivingVia`: ::
+
+ {-# LANGUAGE DeriveGeneric #-}
+ {-# LANGUAGE DerivingStrategies #-}
+ {-# LANGUAGE DerivingVia #-}
+
+ import GHC.Generics
+
+ data V4 a = V4 a a a a
+ deriving
+ stock (Generic, Generic1)
+
+ deriving (Semigroup, Monoid)
+ via Generically (V4 a)
+
+ deriving (Functor, Applicative)
+ via Generically1 V4
+
+The older approach uses :extension:`DeriveGeneric`,
+:extension:`DefaultSignatures`, and :extension:`DeriveAnyClass`. It
+derives instances by providing a distinguished generic implementation
+as part of the type class declaration. This section gives a very brief
+overview of how to do it.
Generic programming support in GHC allows defining classes with methods
that do not need a user specification when instantiating: the method
@@ -248,4 +270,3 @@ original paper [Generics2010]_.
<http://dreixel.net/research/pdf/gdmh.pdf>`__. Proceedings of
the third ACM Haskell symposium on Haskell (Haskell'2010), pp. 37-48,
ACM, 2010.
-