<div dir="ltr">I'd be over the moon with happiness if I could hang COMPLETE pragmas on polymorphic types. <br><br>I have 3 major issues with COMPLETE as it exists.<br><br>1.) Is what is mentioned here:<br><br>Examples for me come up when trying to build a completely unboxed 'linear' library using backpack. In the end I want/need to supply a pattern synonym that works over, say, all the 2d vector types, extracting their elements, but right now I just get spammed by incomplete coverage warnings.<br><br><font face="monospace">type family Elem t :: Type<br></font><div></div><font face="monospace">class D2 where<br></font><div><font face="monospace">  _V2 :: Iso' t (Elem t, Elem t)<br><br>pattern V2 :: D2 t => Elem t -> Elem t -> t<br>pattern V2 a b <- (view _V2 -> (a,b)) where<br>  V2 a b = review _V2 (a,b) <br></font><div><font face="monospace"><br></font></div><div>There is no way to hang a COMPLETE pragma on that.</div><div><br>2.) Another scenario that I'd really love to see supported with COMPLETE pragmas is a way to use | notation with them like you can with MINIMAL pragmas.<br><br></div><div>If you make smart constructors for a dozen constructors in your term type (don't judge me!), you wind up needing 2^12 COMPLETE pragmas to describe all the ways you might mix regular and start constructors today.</div><div><br></div><div><font face="monospace">{# COMPLETE (Lam | LAM), (Var | VAR), ... #-}<br></font><br>would let you get away with a single such definition. This comes up when you have some kind of monoid that acts on terms and you want to push it down through</div><div>the syntax tree invisibly to the user. Explicit substitutions, shifts in position in response to source code edits, etc.</div><div><br>3.) I had one other major usecase where I failed to be able to use a COMPLETE pragma:<br><br>





<font face="monospace">type Option a = (# a | (##) #)<br><br>pattern Some :: a -> Option a<br>pattern Some a = (# a | #)<br><br>pattern None :: Option a<br>pattern None = (# | (##) #)<br><br>{-# COMPLETE Some, None #-}<br><br></font>These worked _within_ a module, but was forgotten across module boundaries, which forced me to rather drastically change the module structure of a package, but it sounds a lot like the issue being discussed. No types to hang it on in the interface file. With the ability to define unlifted newtypes I guess this last one is less of a concern now?<br></div><div><br>-Edward<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 31, 2020 at 2:29 PM Richard Eisenberg <<a href="mailto:rae@richarde.dev">rae@richarde.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Hooray Sebastian!<div><br></div><div>Somehow, I knew cluing you into this conundrum would help find a solution. The approach you describe sounds quite plausible.</div><div><br></div><div>Yet: types *do* matter, of course. So, I suppose the trick is this: have the COMPLETE sets operate independent of types, but then use types in the PM-checker when determining impossible cases? And, about your idea for having pattern synonyms store pointers to their COMPLETE sets: I think data constructors can also participate. But maybe there is always at least one pattern synonym (which would be a reasonable restriction), so I guess you can look at the pattern-match as a whole and use the pattern synonym to find the relevant COMPLETE set(s).</div><div><br></div><div>Thanks for taking a look!</div><div>Richard<br><div><br><blockquote type="cite"><div>On Aug 31, 2020, at 4:23 PM, Sebastian Graf <<a href="mailto:sgraf1337@gmail.com" target="_blank">sgraf1337@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr"><div>Hi Richard,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mo., 31. Aug. 2020 um 21:30 Uhr schrieb Richard Eisenberg <<a href="mailto:rae@richarde.dev" target="_blank">rae@richarde.dev</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Sebastian,<br>
<br>
I enjoyed your presentation last week at ICFP!<br></blockquote><div><br></div><div>Thank you :) I'm glad you liked it!<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This thread (<a href="https://ghc-devs.haskell.narkive.com/NXBBDXg1/suppressing-false-incomplete-pattern-matching-warnings-for-polymorphic-pattern-synonyms" rel="noreferrer" target="_blank">https://ghc-devs.haskell.narkive.com/NXBBDXg1/suppressing-false-incomplete-pattern-matching-warnings-for-polymorphic-pattern-synonyms</a>) played out before you became so interested in pattern-match coverage. I'd be curious for your thoughts there -- do you agree with the conclusions in the thread?<br></blockquote><div><br></div><div>I vaguely remember reading this thread. As you write <a href="https://ghc-devs.haskell.narkive.com/NXBBDXg1/suppressing-false-incomplete-pattern-matching-warnings-for-polymorphic-pattern-synonyms#post9" target="_blank">there</a></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>And, while I know it doesn't work today, what's wrong (in theory) with<br><br>{-# COMPLETE LL #-}<br><br>No types! (That's a rare thing for me to extol...)<br><br>I feel I must be missing something here.</div></blockquote><div><br></div><div>Without reading the whole thread, I think that solution is very possible. The thread goes on to state that we currently attach COMPLETE sets to type constructors, but that is only an implementational thing. I asked Matt (who implemented it) somewhere and he said the only reason to attach it to type constructors was because it was the easiest way to implement serialisation to interface files.</div><div><br></div><div>The thread also mentions that type-directed works better for the pattern-match checker. In fact I disagree; we have to thin out COMPLETE sets all the time anyway when new type evidence comes up, for example. It's quite a hassle to find all the COMPLETE sets of the type constructors a given type can be "represented" (I mean equality modulo type family reductions here) as. I'm pretty sure it's broken in multiple ways, as <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/18276" target="_blank">#18276</a> points out.<br></div></div><div class="gmail_quote"><br><div>Disregarding a bit of busy work for implementing serialisation to interface files, it's probably far simpler to give each COMPLETE set a Name/Unique and refer to them from the pattern synonyms that mention them (we'd have to get creative for orphans, though). The relation is quite like between a type class instance and the type in its head. A more worked example is here: <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/18277#note_287827" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/issues/18277#note_287827</a></div><div><br></div><div>So, it's on my longer term TODO list to fix this.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
My motivation for asking is <a href="https://github.com/conal/linalg/pull/54" rel="noreferrer" target="_blank">https://github.com/conal/linalg/pull/54</a> (you don't need to read the whole thing), which can be boiled down to a request for a COMPLETE pragma that works at a polymorphic result type. (Or a COMPLETE pragma written in a module that is not the defining module for a pattern synonym.) <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/14422" rel="noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/issues/14422</a> describes a similar, but even more challenging scenario.<br></blockquote><div><br></div><div>I'll answer in the thread. (Oh, you also found #14422.) I think the approach above will also fix #14422.<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Do you see any ways forward here?<br></blockquote><div>. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks!<br>
Richard</blockquote><div><br></div><div>Maybe I'll give it a try tomorrow. <br></div></div></div>
</div></blockquote></div><br></div></div>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>