[commit: ghc] ghc-8.0: User's Guide: injective type families section (f66dbdd)

git at git.haskell.org git at git.haskell.org
Fri Jan 8 13:31:29 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/f66dbdd1183a7f8e1e66272850390f4658e23ec7/ghc

>---------------------------------------------------------------

commit f66dbdd1183a7f8e1e66272850390f4658e23ec7
Author: Jan Stolarek <jan.stolarek at p.lodz.pl>
Date:   Fri Jan 8 11:44:18 2016 +0100

    User's Guide: injective type families section
    
    (cherry picked from commit 6f2e722973b39b7ef423f6a6b96725395d561836)


>---------------------------------------------------------------

f66dbdd1183a7f8e1e66272850390f4658e23ec7
 docs/users_guide/glasgow_exts.rst | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index 5808d52..adaf672 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -7022,7 +7022,25 @@ Injective type families
 Starting with GHC 8.0 type families can be annotated with injectivity
 information. This information is then used by GHC during type checking
 to resolve type ambiguities in situations where a type variable appears
-only under type family applications.
+only under type family applications. Consider this contrived example:
+
+::
+
+    type family Id a
+    type instance Id Int = Int
+    type instance Id Bool = Bool
+
+    id :: Id t -> Id t
+    id x = x
+
+Here the definition of ``id`` will be rejected because type variable ``t``
+appears only under type family applications and is thus ambiguous.  But this
+code will be accepted if we tell GHC that ``Id`` is injective, which means it
+will be possible to infer ``t`` at call sites from the type of the argument:
+
+::
+
+    type family Id a = r | r -> a
 
 For full details on injective type families refer to Haskell Symposium
 2015 paper `Injective type families for



More information about the ghc-commits mailing list