summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-03-23 12:06:04 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2018-03-23 12:06:05 -0400
commitaffdea82bb70e5a912b679a169c6e9a230e4c93e (patch)
tree1200f0f3cb2735a45017be61808b709f24c4db49 /docs
parentd5577f44eaf3b9dfdfc77828038782bf818c176a (diff)
downloadhaskell-affdea82bb70e5a912b679a169c6e9a230e4c93e.tar.gz
Allow PartialTypeSignatures in standalone deriving contexts
Summary: At its core, this patch is a simple tweak that allows a user to write: ```lang=haskell deriving instance _ => Eq (Foo a) ``` Which is functionally equivalent to: ```lang=haskell data Foo a = ... deriving Eq ``` But with the added flexibility that `StandaloneDeriving` gives you (namely, the ability to use it anywhere, not just in the same module that `Foo` was declared in). This fixes #13324, and should hopefully address a use case brought up in #10607. Currently, only the use of a single, extra-constraints wildcard is permitted in a standalone deriving declaration. Any other wildcard is rejected, so things like `deriving instance (Eq a, _) => Eq (Foo a)` are currently forbidden. There are quite a few knock-on changes brought on by this change: * The `HsSyn` type used to represent standalone-derived instances was previously `LHsSigType`, which isn't sufficient to hold wildcard types. This needed to be changed to `LHsSigWcType` as a result. * Previously, `DerivContext` was a simple type synonym for `Maybe ThetaType`, under the assumption that you'd only ever be in the `Nothing` case if you were in a `deriving` clause. After this patch, that assumption no longer holds true, as you can also be in this situation with standalone deriving when an extra-constraints wildcard is used. As a result, I changed `DerivContext` to be a proper datatype that reflects the new wrinkle that this patch adds, and plumbed this through the relevant parts of `TcDeriv` and friends. * Relatedly, the error-reporting machinery in `TcErrors` also assumed that if you have any unsolved constraints in a derived instance, then you should be able to fix it by switching over to standalone deriving. This was always sound advice before, but with this new feature, it's possible to have unsolved constraints even when you're standalone-deriving something! To rectify this, I tweaked some constructors of `CtOrigin` a bit to reflect this new subtlety. This requires updating the Haddock submodule. See my fork at https://github.com/RyanGlScott/haddock/commit/067d52fd4be15a1842cbb05f42d9d482de0ad3a7 Test Plan: ./validate Reviewers: simonpj, goldfire, bgamari Reviewed By: simonpj Subscribers: goldfire, rwbarton, thomie, mpickering, carter GHC Trac Issues: #13324 Differential Revision: https://phabricator.haskell.org/D4383
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/8.6.1-notes.rst10
-rw-r--r--docs/users_guide/glasgow_exts.rst23
2 files changed, 31 insertions, 2 deletions
diff --git a/docs/users_guide/8.6.1-notes.rst b/docs/users_guide/8.6.1-notes.rst
index 1e3f509843..04ff09c888 100644
--- a/docs/users_guide/8.6.1-notes.rst
+++ b/docs/users_guide/8.6.1-notes.rst
@@ -21,6 +21,16 @@ Full details
Language
~~~~~~~~
+- GHC now permits the use of a wildcard type as the context of a standalone
+ ``deriving`` declaration with the use of the
+ :extension:`PartialTypeSignatures` language extension. For instance, this
+ declaration: ::
+
+ deriving instance _ => Eq (Foo a)
+
+ Denotes a derived ``Eq (Foo a)`` instance, where the context is inferred in
+ much the same way as ordinary ``deriving`` clauses do.
+ See :ref:`partial-type-signatures`.
- Data declarations with empty ``where`` clauses are no longer valid without the
extension :extension:`GADTSyntax` enabled. For instance, consider the
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index 1717cbb0b2..0cb8a6ae50 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -3908,11 +3908,21 @@ number of important ways:
module as the data type declaration. (But be aware of the dangers of
orphan instances (:ref:`orphan-modules`).
-- You must supply an explicit context (in the example the context is
- ``(Eq a)``), exactly as you would in an ordinary instance
+- In most cases, you must supply an explicit context (in the example the
+ context is ``(Eq a)``), exactly as you would in an ordinary instance
declaration. (In contrast, in a ``deriving`` clause attached to a
data type declaration, the context is inferred.)
+ The exception to this rule is that the context of a standalone deriving
+ declaration can infer its context when a single, extra-wildcards constraint
+ is used as the context, such as in: ::
+
+ deriving instance _ => Eq (Foo a)
+
+ This is essentially the same as if you had written ``deriving Foo`` after
+ the declaration for ``data Foo a``. Using this feature requires the use of
+ :extension:`PartialTypeSignatures` (:ref:`partial-type-signatures`).
+
- Unlike a ``deriving`` declaration attached to a ``data`` declaration,
the instance can be more specific than the data type (assuming you
also use :extension:`FlexibleInstances`, :ref:`instance-rules`). Consider
@@ -11568,6 +11578,15 @@ Anonymous wildcards are also allowed in visible type applications
argument to ``wurble``, then you can say ``wurble @_ @Int`` where the first
argument is a wildcard.
+Standalone ``deriving`` declarations permit the use of a single,
+extra-constraints wildcard, like so: ::
+
+ deriving instance _ => Eq (Foo a)
+
+This denotes a derived ``Eq (Foo a)`` instance where the context is inferred,
+in much the same way that ordinary ``deriving`` clauses do. Any other use of
+wildcards in a standalone ``deriving`` declaration is prohibited.
+
In all other contexts, type wildcards are disallowed, and a named wildcard is treated
as an ordinary type variable. For example: ::