diff options
author | Thomas Winant <thomas.winant@cs.kuleuven.be> | 2015-08-03 14:57:40 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-08-03 14:58:21 +0200 |
commit | d9d2102ea7f6da1bc3a69fa469b89ea843cb8b02 (patch) | |
tree | 82b0177bdb0f2696015b225177ba54eac322fd16 /docs | |
parent | 697079f118197931e7a8c0768e99bf60be4150fd (diff) | |
download | haskell-d9d2102ea7f6da1bc3a69fa469b89ea843cb8b02.tar.gz |
Support wild cards in data/type family instances
Handle anonymous wild cards in type or data family instance
declarations like
unnamed type variables. For instance (pun intented):
type family F (a :: *) (b :: *) :: *
type instance F Int _ = Int
Is now the same as:
type family F (a :: *) (b :: *) :: *
type instance F Int x = Int
Note that unlike wild cards in partial type signatures, no errors (or
warnings
with -XPartialTypeSignatures) are generated for these wild cards, as
there is
nothing interesting to report to the user, i.e. the inferred kind.
Only anonymous wild cards are supported here, named and
extra-constraints wild
card are not.
Test Plan: pass new tests
Reviewers: goldfire, austin, simonpj, bgamari
Reviewed By: simonpj, bgamari
Subscribers: goldfire, thomie
Differential Revision: https://phabricator.haskell.org/D1092
GHC Trac Issues: #3699, #10586
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/7.12.1-notes.xml | 9 | ||||
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 31 |
2 files changed, 40 insertions, 0 deletions
diff --git a/docs/users_guide/7.12.1-notes.xml b/docs/users_guide/7.12.1-notes.xml index e00706c4de..b2cb3699ee 100644 --- a/docs/users_guide/7.12.1-notes.xml +++ b/docs/users_guide/7.12.1-notes.xml @@ -81,6 +81,15 @@ <literal>phantom</literal>, like it is in regular Haskell code. </para> </listitem> + <listitem> + <para> + Wildcards can be used in the type arguments of type/data + family instance declarations to indicate that the name of a + type variable doesn't matter. They will be replaced with new + unique type variables. See <xref + linkend="data-instance-declarations"/> for more details. + </para> + </listitem> </itemizedlist> </sect3> diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index b6c01d6e93..f6a4403950 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -6099,6 +6099,24 @@ data instance GMap (Either a b) v = GMapEither (GMap a v) (GMap b v) can be any number. </para> <para> + When the name of a type argument of a data or newtype instance + declaration doesn't matter, it can be replaced with an underscore + (<literal>_</literal>). This is the same as writing a type variable with + a unique name. +<programlisting> +data family F a b :: * +data instance F Int _ = Int +-- Equivalent to +data instance F Int b = Int +</programlisting> + This resembles the wildcards that can be used in <xref + linkend="partial-type-signatures"/>. However, there are some + differences. Only anonymous wildcards are allowed in these instance + declarations, named and extra-constraints wildcards are not. No error + messages reporting the inferred types are generated, nor does the flag + <option>-XPartialTypeSignatures</option> have any effect. + </para> + <para> Data and newtype instance declarations are only permitted when an appropriate family declaration is in scope - just as a class instance declaration requires the class declaration to be visible. Moreover, each instance @@ -6251,6 +6269,13 @@ type instance Elem [e] = e </para> <para> + Type arguments can be replaced with underscores (<literal>_</literal>) + if the names of the arguments don't matter. This is the same as writing + type variables with unique names. The same rules apply as for <xref + linkend="data-instance-declarations"/>. + </para> + + <para> Type family instance declarations are only legitimate when an appropriate family declaration is in scope - just like class instances require the class declaration to be visible. Moreover, each instance @@ -9413,6 +9438,12 @@ foo (x :: _) = (x :: _) -- Inferred: forall w_. w_ -> w_ </programlisting> +<para> + Anonymous wildcards <emphasis>can</emphasis> occur in type or data instance + declarations. However, these declarations are not partial type signatures + and different rules apply. See <xref linkend="data-instance-declarations"/> + for more details. +</para> <para> Partial type signatures can also be used in <xref linkend="template-haskell"/> splices. |