From 5d7b55731e31c04ba76d670d0176e32f121fc5e4 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Thu, 7 Sep 2006 11:15:40 +0000 Subject: [PATCH] Documentation for impredicative polymorphism --- docs/users_guide/glasgow_exts.xml | 51 ++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index e71d75a..1106790 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -3198,7 +3198,27 @@ for rank-2 types. - + +Impredicative polymorphism + +GHC supports impredicative polymorphism. This means +that you can call a polymorphic function at a polymorphic type, and +parameterise data structures over polymorphic types. For example: + + f :: Maybe (forall a. [a] -> [a]) -> Maybe ([Int], [Char]) + f (Just g) = Just (g [3], g "hello") + f Nothing = Nothing + +Notice here that the Maybe type is parameterised by the +polymorphic type (forall a. [a] -> +[a]). + +The technical details of this extension are described in the paper +Boxy types: +type inference for higher-rank types and impredicativity, +which appeared at ICFP 2006. + + Lexically scoped type variables @@ -3753,7 +3773,13 @@ for these <literal>Terms</literal>: </programlisting> These and many other examples are given in papers by Hongwei Xi, and Tim Sheard. </para> -<para> The extensions to GHC are these: +<para> +The rest of this section outlines the extensions to GHC that support GADTs. +It is far from comprehensive, but the design closely follows that described in +the paper <ulink +url="http://research.microsoft.com/%7Esimonpj/papers/gadt/index.htm">Simple +unification-based type inference for GADTs</ulink>, +which appeared in ICFP 2006. <itemizedlist> <listitem><para> Data type declarations have a 'where' form, as exemplified above. The type signature of @@ -3896,19 +3922,26 @@ the result type of the <literal>case</literal> expression. Hence the addition < <sect1 id="template-haskell"> <title>Template Haskell -Template Haskell allows you to do compile-time meta-programming in Haskell. There is a "home page" for -Template Haskell at -http://www.haskell.org/th/, while -the background to +Template Haskell allows you to do compile-time meta-programming in +Haskell. +The background to the main technical innovations is discussed in " Template Meta-programming for Haskell" (Proc Haskell Workshop 2002). -The details of the Template Haskell design are still in flux. Make sure you -consult the online library reference material + + +There is a Wiki page about +Template Haskell at +http://www.haskell.org/th/, and that is the best place to look for +further details. +You may also +consult the online +Haskell library reference material (search for the type ExpQ). [Temporary: many changes to the original design are described in "http://research.microsoft.com/~simonpj/tmp/notes2.ps". -Not all of these changes are in GHC 6.2.] +Not all of these changes are in GHC 6.6.] The first example from that paper is set out below as a worked example to help get you started. -- 1.7.10.4