<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin-top:6.0pt;
margin-right:0cm;
margin-bottom:6.0pt;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:6.0pt;
margin-right:0cm;
margin-bottom:6.0pt;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
p.Code, li.Code, div.Code
{mso-style-name:Code;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:22.7pt;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-language:EN-US;
font-weight:bold;}
span.EmailStyle20
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:630094513;
mso-list-type:hybrid;
mso-list-template-ids:1910117180 134807573 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l1
{mso-list-id:690640945;
mso-list-template-ids:1045955376;}
@list l1:level1
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:36.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level2
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:72.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level3
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:108.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level4
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:144.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level5
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:180.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level6
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:216.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level7
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:252.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level8
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:288.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level9
{mso-level-number-format:alpha-upper;
mso-level-tab-stop:324.0pt;
mso-level-number-position:left;
text-indent:-18.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Dear Steering Committee<o:p></o:p></p>
<p class="MsoNormal">You may remember that we approved the <a href="https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0126-type-applications-in-patterns.rst">
Type Applications in Patterns</a> proposal, some time ago. Cale has been implementing it (see
<a href="https://gitlab.haskell.org/ghc/ghc/-/issues/11350">ticket 11350</a> and <a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2464">
MR 2464</a>). It’s nearly done.<o:p></o:p></p>
<p class="MsoNormal">But in doing so, one design choice came up that we did not discuss much, and I’d like to consult you.<o:p></o:p></p>
<p class="MsoNormal">Consider first the <i>existing</i> pattern-signature mechanism (not the new feature):<o:p></o:p></p>
<p class="Code">data T a where<o:p></o:p></p>
<p class="Code">MkT :: forall a b. a -> b -> T a<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="Code">f1 :: forall p. T [p] -> blah<o:p></o:p></p>
<p class="Code">f1 (MkT (x :: a) pi) = blah<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="Code">f2 :: forall p. T [p] -> blah<o:p></o:p></p>
<p class="Code">f2 (MkT (x :: p) pi) = blah<o:p></o:p></p>
<p class="MsoNormal">In f1, the pattern (x :: a) brings ‘a’ into scope, binding it to the type [p]. But in f2, since p is already in scope, the pattern (x :: p) does not bring anything new into scope. Instead it requires that x have type p, but actually it
has type [p], so f2 is rejected.<o:p></o:p></p>
<p class="MsoNormal">Notice that a pattern signature brings a new variable into scope only if it isn’t already in scope. Notice how this differs from the treatment of term variables; the ‘pi’ in the pattern brings ‘pi’ into scope unconditionally, shadowing
the existing ‘pi’ (from the Prelude).<o:p></o:p></p>
<p class="MsoNormal">OK, now let’s look at the new feature. Consider<o:p></o:p></p>
<p class="Code">g1 :: forall p. T [p] -> blah<o:p></o:p></p>
<p class="Code">g1 (MkT @a x y) = blah<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="Code">g2 :: forall p. T [p] -> blah<o:p></o:p></p>
<p class="Code">g2 (MkT @p x pi) = blah<o:p></o:p></p>
<p class="Code"><o:p> </o:p></p>
<p class="MsoNormal"><b>Question</b>: should the variables free in these type arguments be treated like pattern signatures, or like term variables?<o:p></o:p></p>
<ol style="margin-top:0cm" start="1" type="A">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo3"><b>Like pattern signatures</b>. In this design, in g1, ‘a’ is not in scope, so this brings it into scope, bound to [p]. But in g2, ‘p’ is in scope, so this is rejected (because
MkT is instantiated at [p] not p.<o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo3"><b>Like term variables</b>. In this design, all the variables free in type patterns are fresh, and brought into scope. In g2, a new ‘p’ is brought into scope, shadowing the existing
‘p’; indeed the new ‘p’ is bound to [old_p].<o:p></o:p></li></ol>
<p class="MsoNormal">The original paper, and hence the accepted proposal, adopts (A). But Cale likes (B). Indeed John Ericson wrote a
<a href="https://github.com/ghc-proposals/ghc-proposals/pull/291">Proposal 291: simplify scoping for type applications in pattens</a> to advocate this change. (The proposal is not easy to understand, but advocating (B) is its payload.<o:p></o:p></p>
<p class="MsoNormal">This is not a terribly big deal, but it would be good to settle it. <o:p></o:p></p>
<p class="MsoNormal">The right place to have debate is on <a href="https://github.com/ghc-proposals/ghc-proposals/pull/291">
Proposal 291</a>. This email is just to alert you to it, and ask for your opinions.<o:p></o:p></p>
<p class="MsoNormal">Simon<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>