diff options
author | Thomas Winant <thomas.winant@cs.kuleuven.be> | 2015-07-20 15:43:53 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-07-20 16:43:34 +0200 |
commit | 49373ffe4cbc87b46468d2372e850138e151a9ae (patch) | |
tree | c5b5f74bc06eb924b4d75f10b370a3b3e49a972b /docs | |
parent | 82ffc80df573512f788524c4616db3c08fc9f125 (diff) | |
download | haskell-49373ffe4cbc87b46468d2372e850138e151a9ae.tar.gz |
Support wild cards in TH splices
- Declaration splices: partial type signatures are fully supported in TH
declaration splices.
For example, the wild cards in the example below will unify with `Eq
a`
and `a -> a -> Bool`, as expected:
```
[d| foo :: _ => _
foo x y = x == y |]
```
- Expression splices: anonymous and named wild cards are supported in
expression signatures, but extra-constraints wild cards aren't. Just
as is the case for regular expression signatures.
```
[e | Just True :: _a _ |]
```
- Typed expression splices: the same wildcards as in (untyped)
expression splices are supported.
- Pattern splices: TH doesn't support type signatures in pattern
splices, consequently, partial type signatures aren't supported
either.
- Type splices: partial type signatures are only partially supported in
type splices, specifically: only anonymous wild cards are allowed.
So `[t| _ |]`, `[t| _ -> Maybe _ |]` will work, but `[t| _ => _ |]` or
`[| _a |]` won't (without `-XNamedWildCards`, the latter will work as
the named wild card is treated as a type variable).
Normally, named wild cards are collected before renaming a (partial)
type signature. However, TH type splices are run during renaming, i.e.
after the initial traversal, leading to out of scope errors for named
wild cards. We can't just extend the initial traversal to collect the
named wild cards in TH type splices, as we'd need to expand them,
which is supposed to happen only once, during renaming.
Similarly, the extra-constraints wild card is handled right before
renaming too, and is therefore also not supported in a TH type splice.
Another reason not to support extra-constraints wild cards in TH type
splices is that a single signature can contain many TH type splices,
whereas it mustn't contain more than one extra-constraints wild card.
Enforcing would this be hard the way things are currently organised.
Anonymous wild cards pose no problem, because they start without names
and are given names during renaming. These names are collected right
after renaming. The names generated for anonymous wild cards in TH
type splices will thus be collected as well.
With a more invasive refactoring of the renaming, partial type
signatures could be fully supported in TH type splices. As only
anonymous wild cards have been requested so far, these small changes
satisfying this request will do for now. Also don't forget that a TH
declaration splices support all kinds of wild cards.
- Extra-constraints wild cards were silently ignored in expression and
pattern signatures, appropriate error messages are now generated.
Test Plan: run new tests
Reviewers: austin, goldfire, adamgundry, bgamari
Reviewed By: goldfire, adamgundry, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1048
GHC Trac Issues: #10094, #10548
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/7.12.1-notes.xml | 7 | ||||
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 41 |
2 files changed, 46 insertions, 2 deletions
diff --git a/docs/users_guide/7.12.1-notes.xml b/docs/users_guide/7.12.1-notes.xml index cc9dd37dbb..cfe98b530b 100644 --- a/docs/users_guide/7.12.1-notes.xml +++ b/docs/users_guide/7.12.1-notes.xml @@ -130,7 +130,12 @@ Splices and quasi-quotes continue to only be supported by a stage 2 compiler. </para> - </listitem> + </listitem> + <listitem> + <para> + Partial type signatures can now be used in splices, see <xref linkend="pts-where"/>. + </para> + </listitem> </itemizedlist> </sect3> diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index a9a85fa5ea..2ec1d4e7b5 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -9397,6 +9397,7 @@ Extra-constraints wildcards cannot be named. Partial type signatures are allowed for bindings, pattern and expression signatures. In all other contexts, e.g. type class or type family declarations, they are disallowed. In the following example a wildcard is used in each of the three possible contexts. +Extra-constraints wildcards are not supported in pattern or expression signatures. </para> <programlisting> {-# LANGUAGE ScopedTypeVariables #-} @@ -9404,6 +9405,43 @@ foo :: _ foo (x :: _) = (x :: _) -- Inferred: forall w_. w_ -> w_ </programlisting> + + +<para> +Partial type signatures can also be used in <xref linkend="template-haskell"/> splices. +</para> + +<itemizedlist> + <listitem>Declaration splices: partial type signature are fully supported. +<programlisting> +{-# LANGUAGE TemplateHaskell, NamedWildCards #-} +$( [d| foo :: _ => _a -> _a -> _ + foo x y = x == y|] ) +</programlisting> + </listitem> + <listitem>Expression splices: anonymous and named wildcards can be used in expression signatures. + Extra-constraints wildcards are not supported, just like in regular expression signatures. +<programlisting> +{-# LANGUAGE TemplateHaskell, NamedWildCards #-} +$( [e| foo = (Just True :: _m _) |] ) +</programlisting> + </listitem> + <listitem>Typed expression splices: the same wildcards as in (untyped) expression splices are supported. + </listitem> + <listitem>Pattern splices: Template Haskell doesn't support type signatures in pattern splices. + Consequently, partial type signatures are not supported either. + </listitem> + <listitem>Type splices: only anonymous wildcards are supported in type splices. + Named and extra-constraints wildcards are not. +<programlisting> +{-# LANGUAGE TemplateHaskell #-} +foo :: $( [t| _ |] ) -> a +foo x = x +</programlisting> + </listitem> +</itemizedlist> + + </sect2> </sect1> <!-- ==================== Deferring type errors ================= --> @@ -9589,7 +9627,8 @@ Wiki page</ulink>. the quotation has type <literal>Q Type</literal>.</para></listitem> <listitem><para> <literal>[p| ... |]</literal>, where the "..." is a pattern; the quotation has type <literal>Q Pat</literal>.</para></listitem> - </itemizedlist></para></listitem> + </itemizedlist> + See <xref linkend="pts-where"/> for using partial type signatures in quotations.</para></listitem> <listitem> <para> |