summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorReid Barton <rwbarton@gmail.com>2017-02-05 20:24:06 -0500
committerBen Gamari <ben@smart-cactus.org>2017-02-05 20:26:55 -0500
commit0abe7361249b0b4dc43dc66547451da8916b30bf (patch)
treeca168e80f1b09bf2216aade612fc2c48dd58421d /docs
parentfbcef83a3aa130d976a201f2a21c5afc5a43d000 (diff)
downloadhaskell-0abe7361249b0b4dc43dc66547451da8916b30bf.tar.gz
Don't replace type family instances with the same LHS in GHCi (#7102)
This fixes the easy part of #7102 by removing the logic that lets the user replace a type family instance with a new one with the same LHS. As discussed on that ticket, this is unsound in general. Better to have the user redefine the type family from scratch. The example from comment:7 involving loading modules into ghci is not fixed yet; it actually doesn't rely on the instances having the same LHS. This commit adds an expect_broken test for that example as well. Test Plan: T7102a for the fix; T7102 is the test not fixed yet Reviewers: dfeuer, austin, bgamari, goldfire Reviewed By: dfeuer Subscribers: dfeuer, thomie Differential Revision: https://phabricator.haskell.org/D2994
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/ghci.rst38
1 files changed, 33 insertions, 5 deletions
diff --git a/docs/users_guide/ghci.rst b/docs/users_guide/ghci.rst
index 1e53b6c32c..fa00b80244 100644
--- a/docs/users_guide/ghci.rst
+++ b/docs/users_guide/ghci.rst
@@ -655,11 +655,39 @@ The old, shadowed, version of ``T`` is displayed as
``main::Interactive.T`` by GHCi in an attempt to distinguish it from the
new ``T``, which is displayed as simply ``T``.
-Class and type-family instance declarations are simply added to the list
-of available instances, with one exception. Since you might want to
-re-define one, a class or type-family instance *replaces* any earlier
-instance with an identical head or left hand side (respectively). (See
-:ref:`type-families`.)
+Class and type-family instance declarations are simply added to the
+list of available instances, with one exception. Since you might want
+to re-define one, a class instance *replaces* any earlier instance
+with an identical head. You aren't allowed to re-define a type family
+instance, since it might not be type safe to do so. Instead, re-define
+the whole type-family. (See :ref:`type-families`.) For example:
+
+.. code-block:: none
+
+ Prelude> type family T a b
+ Prelude> type instance T a b = a
+ Prelude> let uc :: a -> T a b; uc = id
+
+ Prelude> type instance T a b = b
+
+ <interactive>:3:15: error:
+ Conflicting family instance declarations:
+ T a b = a -- Defined at <interactive>:3:15
+ T a b = b -- Defined at <interactive>:5:15
+
+ -- Darn! We have to re-declare T.
+
+ Prelude> type family T a b
+ -- This is a brand-new T, unrelated to the old one
+ Prelude> type instance T a b = b
+ Prelude> uc 'a' :: Int
+
+ <interactive>:8:1: error:
+ • Couldn't match type ‘Char’ with ‘Int’
+ Expected type: Int
+ Actual type: Ghci1.T Char b0
+ • In the expression: uc 'a' :: Int
+ In an equation for ‘it’: it = uc 'a' :: Int
.. _ghci-scope: