<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<pre class="moz-quote-pre" wrap="">> In the case where all the patterns are polymorphic, a user must
> provide a type signature but we accept the definition regardless of
> the type signature they provide. </pre>
<p>Currently we can specify the type *constructor* in a COMPLETE
pragma:</p>
<pre><tt>pattern J :: a -> Maybe a</tt><tt>
</tt><tt>pattern J a = Just a</tt><tt>
</tt><tt>
</tt><tt>pattern N :: Maybe a</tt><tt>
</tt><tt>pattern N = Nothing</tt><tt>
</tt><tt>
</tt><tt>{-# COMPLETE N, J :: Maybe #-}</tt><tt>
</tt></pre>
<p><br>
</p>
<p>Instead if we could specify the type with its free vars, we could
refer to them in conlike signatures:</p>
<pre><span class="p">{-# COMPLETE N, [</span><span class="p"><span class="kt"> J</span></span><span class="p"><span class="kt"></span> <span class="ow">::</span> a -> Maybe a ] :: Maybe a #-}</span></pre>
<p>The COMPLETE pragma for LL could be:<span class="p"></span><br>
<span class="p"></span></p>
<pre><pre><span class="p">{-# COMPLETE [</span><span class="p"><span class="kt"> LL</span> <span class="ow">::</span> <span class="kt">HasSrcSpan</span> a <span class="ow">=></span> <span class="kt">SrcSpan</span> <span class="ow">-></span> <span class="kt">SrcSpanLess</span> a <span class="ow">-></span> a ] :: a #-}
</span></pre></pre>
<br>
<p>I'm borrowing the list comprehension syntax on purpose because it
would allow to define a set of conlikes from a type-list (see my
request [1]):<span class="p"></span><br>
<span class="p"></span></p>
<pre><pre><span class="p">{-# COMPLETE [</span><span class="p"><span class="kt"> V</span> <span class="ow">::</span> </span><span class="p"><span class="p">(c :< cs) => c -> Variant cs</span>
| c <- cs
] :: Variant cs
#-}</span>
</pre>
> To make things more formal, when the pattern-match checker
> requests a set of constructors for some data type constructor T, the
> checker returns:
>
> * The original set of data constructors for T
> * Any COMPLETE sets of type T
>
> Note the use of the phrase <b class="moz-txt-star"><span class="moz-txt-tag">*</span>type constructor<span class="moz-txt-tag">*</span></b>. The return type of all
> constructor-like things in a COMPLETE set must all be headed by the
> same type constructor T. Since `LL`'s return type is simply a type
> variable `a`, this simply doesn't work with the design of COMPLETE
> sets.
</pre>
<p>Could we use a mechanism similar to instance resolution (with
FlexibleInstances) for the checker to return matching COMPLETE
sets instead?</p>
<pre>
--Sylvain
[1] <a class="moz-txt-link-freetext" href="https://mail.haskell.org/pipermail/ghc-devs/2018-July/016053.html">https://mail.haskell.org/pipermail/ghc-devs/2018-July/016053.html</a>
<span class="p"></span></pre>
</body>
</html>