Skip to content

Commit

Permalink
Add explanation for GHC-87139.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmikus authored and BinderDavid committed Jun 17, 2024
1 parent f7c49e5 commit c085855
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE DerivingStrategies #-}
module IllegalDerivingStrategy where

newtype Year = MkYear Int
deriving newtype Show
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module IllegalDerivingStrategy where

newtype Year = MkYear Int
deriving newtype Show
27 changes: 27 additions & 0 deletions message-index/messages/GHC-87139/illegalDerivingStrategy/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Illegal deriving strategy on newtype
---

In this example, there is a deriving clause instructing GHC
to derive a `Show` instance for the newtype `Year`.

There are (at least) two different ways to derive such a `Show`
instance. The `stock` strategy is the standard generic way of
deriving `Show` instances for datatypes. The `newtype` strategy
is available for `newtype`s and simply uses the existing instance
of the underlying type, in this case `Int`.

The difference in the current example is that the `stock`-derived
`show` includes the constructor name, the `newtype`-derived does
not.

If multiple strategies are available, GHC chooses a default. In
the case of `deriving` for classes for which `stock`-deriving is
available, such as `Show`, `stock` is the default. If you want to
be explicit about this or explicitly deviate from the default,
you can specify a strategy explicitly.

This, however, requires the `DerivingStrategies` language extension
to be enabled, and if it is not, you will get an error. The fix in
this case is to enable the language extension, for example via a
compiler pragma.
12 changes: 12 additions & 0 deletions message-index/messages/GHC-87139/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Illegal deriving strategy
summary: Use of a deriving strategy without enabling the corresponding language extension
severity: error
introduced: 9.8.1
---

This error occurs if the syntax for specifying a deriving strategy
is being used without having the corresponding language extension enabled.

The fix is usually to either enable the language extension, or to remove
the deriving strategy (if it happens to match the default).

0 comments on commit c085855

Please sign in to comment.