[commit: ghc] master: User's Guide: injective type families section (6f2e722)

git at git.haskell.org git at git.haskell.org
Fri Jan 8 10:43:41 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/6f2e722973b39b7ef423f6a6b96725395d561836/ghc

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

commit 6f2e722973b39b7ef423f6a6b96725395d561836
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


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

6f2e722973b39b7ef423f6a6b96725395d561836
 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 836b188..377c1b5 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