summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsad Saeeduddin <masaeedu@gmail.com>2020-12-26 20:03:05 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-02 07:37:09 -0500
commitcc87bda6739b2f10ef097759ee5de45a97afbe66 (patch)
tree536fea03df26b7ed743f57e8c68c4959fd6d6b3e
parentaa17b84dab91408090f079f85d62ef3221f4ab88 (diff)
downloadhaskell-cc87bda6739b2f10ef097759ee5de45a97afbe66.tar.gz
Use EmptyCase instead of undefined in Generics example
Fixes #19124
-rw-r--r--libraries/base/GHC/Generics.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/libraries/base/GHC/Generics.hs b/libraries/base/GHC/Generics.hs
index d4c8f73995..09d8fe1bfe 100644
--- a/libraries/base/GHC/Generics.hs
+++ b/libraries/base/GHC/Generics.hs
@@ -317,17 +317,17 @@ module GHC.Generics (
--
-- |
--
--- The instance for 'V1' is slightly awkward (but also rarely used):
+-- To deal with the 'V1' case, we use the following code (which requires the pragma @EmptyCase@):
--
-- @
-- instance Encode' 'V1' where
--- encode' x = undefined
+-- encode' x = case x of { }
-- @
--
--- There are no values of type @V1 p@ to pass (except undefined), so this is
--- actually impossible. One can ask why it is useful to define an instance for
--- 'V1' at all in this case? Well, an empty type can be used as an argument to
--- a non-empty type, and you might still want to encode the resulting type.
+-- There are no values of type @V1 p@ to pass, so it is impossible for this
+-- function to be invoked. One can ask why it is useful to define an instance
+-- for 'V1' at all in this case? Well, an empty type can be used as an argument
+-- to a non-empty type, and you might still want to encode the resulting type.
-- As a somewhat contrived example, consider @[Empty]@, which is not an empty
-- type, but contains just the empty list. The 'V1' instance ensures that we
-- can call the generic function on such types.