From feaa31fbc41685d69045ac8d34be4e18f4f27ffd Mon Sep 17 00:00:00 2001
From: Ben Gamari
Date: Mon, 5 Sep 2016 19:19:23 0400
Subject: [PATCH] Remove references to XRelaxedPolyRec
Test Plan: Read it
Reviewers: dfeuer, austin
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2515
GHC Trac Issues: #11691

docs/users_guide/bugs.rst  51 +++++++++++++++++++++++++
docs/users_guide/glasgow_exts.rst  62 
utils/mkUserGuidePart/Options/Language.hs  8 
3 files changed, 51 insertions(+), 70 deletions()
diff git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index 5d30363..875820b 100644
 a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ 126,6 +126,57 @@ been decided to remove them from the next version of the language
standard. This behaviour can be controlled with the ``DatatypeContexts``
extension. See :ref:`datatypecontexts`.
+.. _infelicitiesrecursivegroups:
+
+Typechecking of recursive binding groups
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Haskell Report specifies that a group of bindings (at top level, or
+in a ``let`` or ``where``) should be sorted into stronglyconnected
+components, and then typechecked in dependency order
+(`Haskell Report, Section
+4.5.1 `__). As
+each group is typechecked, any binders of the group that have an
+explicit type signature are put in the type environment with the
+specified polymorphic type, and all others are monomorphic until the
+group is generalised (`Haskell Report, Section
+4.5.2 `__).
+
+Following a suggestion of Mark Jones, in his paper `Typing Haskell in
+Haskell `__, GHC implements a
+more general scheme. In GHC *the dependency analysis ignores references to
+variables that have an explicit type signature*. As a result of this refined
+dependency analysis, the dependency groups are smaller, and more bindings will
+typecheck. For example, consider: ::
+
+ f :: Eq a => a > Bool
+ f x = (x == x)  g True  g "Yes"
+
+ g y = (y <= y)  f True
+
+This is rejected by Haskell 98, but under Jones's scheme the definition
+for ``g`` is typechecked first, separately from that for ``f``, because
+the reference to ``f`` in ``g``\'s right hand side is ignored by the
+dependency analysis. Then ``g``\'s type is generalised, to get ::
+
+ g :: Ord a => a > Bool
+
+Now, the definition for ``f`` is typechecked, with this type for ``g``
+in the type environment.
+
+The same refined dependency analysis also allows the type signatures of
+mutuallyrecursive functions to have different contexts, something that is
+illegal in Haskell 98 (Section 4.5.2, last sentence). GHC only insists that the
+type signatures of a *refined* group have identical type signatures; in practice
+this means that only variables bound by the same pattern binding must have the
+same context. For example, this is fine: ::
+
+ f :: Eq a => a > Bool
+ f x = (x == x)  g True
+
+ g :: Ord a => a > Bool
+ g y = (y <= y)  f True
+
.. _infelicitiesModules:
Module system and interface files
diff git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index 7709b22..6209548 100644
 a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ 8412,7 +8412,6 @@ Lexically scoped type variables
.. ghcflag:: XScopedTypeVariables
 :implies: :ghcflag:`XRelaxedPolyRec`
:implies: :ghcflag:`XExplicitForAll`
Enable lexical scoping of type variables explicitly introduced with
@@ 8436,9 +8435,6 @@ signature for ``ys``. In Haskell 98 it is not possible to declare a type
for ``ys``; a major benefit of scoped type variables is that it becomes
possible to do so.
Lexicallyscoped type variables are enabled by
:ghcflag:`XScopedTypeVariables`. This flag implies :ghcflag:`XRelaxedPolyRec`.

Overview

@@ 8651,64 +8647,6 @@ the Haskell Report) can be completely switched off by
restriction is switched off by default in GHCi's interactive options
(see :ref:`ghciinteractiveoptions`).
.. _typingbinds:

Generalised typing of mutually recursive bindings


.. ghcflag:: XRelaxedPolyRec

 Allow the typechecker to ignore references to bindings with
 explicit type signatures.

The Haskell Report specifies that a group of bindings (at top level, or
in a ``let`` or ``where``) should be sorted into stronglyconnected
components, and then typechecked in dependency order
(`Haskell Report, Section
4.5.1 `__). As
each group is typechecked, any binders of the group that have an
explicit type signature are put in the type environment with the
specified polymorphic type, and all others are monomorphic until the
group is generalised (`Haskell Report, Section
4.5.2 `__).

Following a suggestion of Mark Jones, in his paper `Typing Haskell in
Haskell `__, GHC implements a
more general scheme. If :ghcflag:`XRelaxedPolyRec` is specified: *the
dependency analysis ignores references to variables that have an
explicit type signature*. As a result of this refined dependency
analysis, the dependency groups are smaller, and more bindings will
typecheck. For example, consider: ::

 f :: Eq a => a > Bool
 f x = (x == x)  g True  g "Yes"

 g y = (y <= y)  f True

This is rejected by Haskell 98, but under Jones's scheme the definition
for ``g`` is typechecked first, separately from that for ``f``, because
the reference to ``f`` in ``g``\'s right hand side is ignored by the
dependency analysis. Then ``g``\'s type is generalised, to get ::

 g :: Ord a => a > Bool

Now, the definition for ``f`` is typechecked, with this type for ``g``
in the type environment.

The same refined dependency analysis also allows the type signatures of
mutuallyrecursive functions to have different contexts, something that
is illegal in Haskell 98 (Section 4.5.2, last sentence). With
:ghcflag:`XRelaxedPolyRec` GHC only insists that the type signatures of a
*refined* group have identical type signatures; in practice this means
that only variables bound by the same pattern binding must have the same
context. For example, this is fine: ::

 f :: Eq a => a > Bool
 f x = (x == x)  g True

 g :: Ord a => a > Bool
 g y = (y <= y)  f True

.. _monolocalbinds:
Letgeneralisation
diff git a/utils/mkUserGuidePart/Options/Language.hs b/utils/mkUserGuidePart/Options/Language.hs
index 0d9014e..c2012af 100644
 a/utils/mkUserGuidePart/Options/Language.hs
+++ b/utils/mkUserGuidePart/Options/Language.hs
@@ 603,14 +603,6 @@ languageOptions =
, flagReverse = "XNoRecursiveDo"
, flagSince = "6.8.1"
}
 , flag { flagName = "XRelaxedPolyRec"
 , flagDescription =
 "*(deprecated)* Relaxed checking for :ref:`mutuallyrecursive "++
 "polymorphic functions `."
 , flagType = DynamicFlag
 , flagReverse = "XNoRelaxedPolyRec"
 , flagSince = "6.8.1"
 }
, flag { flagName = "XRoleAnnotations"
, flagDescription =
"Enable :ref:`role annotations `."

1.9.1