<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">This thread was one of the reasons I posted <a href="https://github.com/ghc-proposals/ghc-proposals/pull/378" class="">https://github.com/ghc-proposals/ghc-proposals/pull/378</a>, which advocates for accepting #291 (again, with significant changes to clarify the text).<div class=""><br class=""></div><div class="">I thus think that the better choice would be "(B) like term variables", as I hope for there not to be a distinction between types and terms in the future.</div><div class=""><br class=""></div><div class="">I admit that (B) is less expressive than (A) and would welcome a proposal allowing for parameterized patterns that can take inputs as well as producing outputs -- among both terms and types.</div><div class=""><br class=""></div><div class="">Richard<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 13, 2020, at 11:10 AM, Iavor Diatchki <<a href="mailto:iavor.diatchki@gmail.com" class="">iavor.diatchki@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello Simon,<div class=""><br class=""></div><div class="">I think that the consistent choice would be "(A) like pattern signatures".   I think this would ensure that all types in patterns handle variables in the same way.  It would be confusing to me if the following two examples ended up doing different things:</div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><font face="monospace" class="">h1 (Nothing :: Maybe [p]) = ...</font></div><div class=""><font face="monospace" class="">h2 (Nothing @[p]) = ...</font></div><div class=""><br class=""></div><div class="">-Iavor</div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 13, 2020 at 3:30 AM Simon Peyton Jones via ghc-steering-committee <<a href="mailto:ghc-steering-committee@haskell.org" class="">ghc-steering-committee@haskell.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-GB" style="overflow-wrap: break-word;" class="">
<div class="gmail-m_-259128659515729648WordSection1"><p class="MsoNormal">Dear Steering Committee<u class=""></u><u class=""></u></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" target="_blank" class="">
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" target="_blank" class="">ticket 11350</a> and <a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2464" target="_blank" class="">
MR 2464</a>).    It’s nearly done.<u class=""></u><u class=""></u></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.<u class=""></u><u class=""></u></p><p class="MsoNormal">Consider first the <i class="">existing</i> pattern-signature mechanism (not the new feature):<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">data T a where<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">MkT :: forall a b. a -> b -> T a<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code"><u class=""></u> <u class=""></u></p><p class="gmail-m_-259128659515729648Code">f1 :: forall p. T [p] -> blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">f1 (MkT (x :: a) pi) = blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code"><u class=""></u> <u class=""></u></p><p class="gmail-m_-259128659515729648Code">f2 :: forall p. T [p] -> blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">f2 (MkT (x :: p) pi) = blah<u class=""></u><u class=""></u></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.<u class=""></u><u class=""></u></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).<u class=""></u><u class=""></u></p><p class="MsoNormal">OK, now let’s look at the new feature. Consider<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">g1 :: forall p. T [p] -> blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">g1 (MkT @a x y) = blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code"><u class=""></u> <u class=""></u></p><p class="gmail-m_-259128659515729648Code">g2 :: forall p. T [p] -> blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code">g2 (MkT @p x pi) = blah<u class=""></u><u class=""></u></p><p class="gmail-m_-259128659515729648Code"><u class=""></u> <u class=""></u></p><p class="MsoNormal"><b class="">Question</b>: should the variables free in these type arguments be treated like pattern signatures, or like term variables?<u class=""></u><u class=""></u></p>
<ol style="margin-top:0cm" start="1" type="A" class="">
<li class="gmail-m_-259128659515729648MsoListParagraph" style="margin-left:0cm"><b class="">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.<u class=""></u><u class=""></u></li><li class="gmail-m_-259128659515729648MsoListParagraph" style="margin-left:0cm"><b class="">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].<u class=""></u><u class=""></u></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" target="_blank" class="">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.<u class=""></u><u class=""></u></p><p class="MsoNormal">This is not a terribly big deal, but it would be good to settle it.   <u class=""></u><u class=""></u></p><p class="MsoNormal">The right place to have debate is on <a href="https://github.com/ghc-proposals/ghc-proposals/pull/291" target="_blank" class="">
Proposal 291</a>.  This email is just to alert you to it, and ask for your opinions.<u class=""></u><u class=""></u></p><p class="MsoNormal">Simon<u class=""></u><u class=""></u></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
</div>

_______________________________________________<br class="">
ghc-steering-committee mailing list<br class="">
<a href="mailto:ghc-steering-committee@haskell.org" target="_blank" class="">ghc-steering-committee@haskell.org</a><br class="">
<a href="https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee" rel="noreferrer" target="_blank" class="">https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee</a><br class="">
</blockquote></div>
_______________________________________________<br class="">ghc-steering-committee mailing list<br class=""><a href="mailto:ghc-steering-committee@haskell.org" class="">ghc-steering-committee@haskell.org</a><br class="">https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee<br class=""></div></blockquote></div><br class=""></div></body></html>