diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-09-02 15:32:56 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-09-02 15:32:57 -0400 |
commit | 6330b0b0938bc7b27463b3bbfa0df661e4a966b1 (patch) | |
tree | 89962f2318c4d843e640b18d3a4e29e4b6517996 /libraries | |
parent | 590e7376de357a61555181d78f5201cf2f503aa5 (diff) | |
download | haskell-6330b0b0938bc7b27463b3bbfa0df661e4a966b1.tar.gz |
Document the intricacies of ForallC variable quantification better
Summary:
I recently (re-)discovered that `ForallC` quantifies different type variables
depending on whether `GadtC` is present or not. This is an important
enough gotcha where I feel like this fact should also be advertised in the
`template-haskell` documentation itself, so this patch does just that.
Test Plan: Read it
Reviewers: goldfire, austin, bgamari
Subscribers: rwbarton, thomie
GHC Trac Issues: #13885
Differential Revision: https://phabricator.haskell.org/D3880
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index aacc8c3db1..3087c69504 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -1833,6 +1833,35 @@ data DecidedStrictness = DecidedLazy | DecidedUnpack deriving (Show, Eq, Ord, Data, Generic) +-- | A single data constructor. +-- +-- The constructors for 'Con' can roughly be divided up into two categories: +-- those for constructors with \"vanilla\" syntax ('NormalC', 'RecC', and +-- 'InfixC'), and those for constructors with GADT syntax ('GadtC' and +-- 'RecGadtC'). The 'ForallC' constructor, which quantifies additional type +-- variables and class contexts, can surround either variety of constructor. +-- However, the type variables that it quantifies are different depending +-- on what constructor syntax is used: +-- +-- * If a 'ForallC' surrounds a constructor with vanilla syntax, then the +-- 'ForallC' will only quantify /existential/ type variables. For example: +-- +-- @ +-- data Foo a = forall b. MkFoo a b +-- @ +-- +-- In @MkFoo@, 'ForallC' will quantify @b@, but not @a@. +-- +-- * If a 'ForallC' surrounds a constructor with GADT syntax, then the +-- 'ForallC' will quantify /all/ type variables used in the constructor. +-- For example: +-- +-- @ +-- data Bar a b where +-- MkBar :: (a ~ b) => c -> MkBar a b +-- @ +-- +-- In @MkBar@, 'ForallC' will quantify @a@, @b@, and @c@. data Con = NormalC Name [BangType] -- ^ @C Int a@ | RecC Name [VarBangType] -- ^ @C { v :: Int, w :: a }@ | InfixC BangType Name BangType -- ^ @Int :+ a@ |