<div dir="ltr"><br><br><div class="gmail_quote">On Tue, Oct 14, 2008 at 6:37 PM, Daniel Gorín <span dir="ltr">&lt;<a href="mailto:dgorin@dc.uba.ar">dgorin@dc.uba.ar</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style=""><br><div><div class="Ih2E3d"><div>On Oct 14, 2008, at 10:19 PM, Jason Dagit wrote:</div><blockquote type="cite"><div dir="ltr"><br><div class="gmail_quote">On Tue, Oct 14, 2008 at 7:27 AM, Daniel Gorín <span dir="ltr">&lt;<a href="mailto:dgorin@dc.uba.ar" target="_blank">dgorin@dc.uba.ar</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi<br> <br> After installing ghc 6.10-rc, I have a program that no longer compiles. I get the dreaded &quot;GADT pattern match....&quot; error, instead :)<br>
 <br> Here is a boiled-down example:</blockquote></div></div></blockquote></div><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<span>[...]</span></blockquote></div></div></blockquote><div class="Ih2E3d"><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div><br>I don&#39;t have 6.10 handy to try out your program, but in 6.8 and older the type error message you&#39;re getting means that the compiler needs more &quot;outside in&quot; help with type checking this.<br>
 <br>Usually this means adding type more type signatures on the outside.&nbsp; For example, maybe you need to give the type signatures inside the case to make the types inside the pattern matches of the case more rigid.&nbsp; That probably didn&#39;t make a lot of sense :(&nbsp; So here is an example,<br>
 <br>case wit :: {- Try adding a signature here -} of ... <br><br>Given that your code has such deep pattern nesting I would argue that it is in your best interest to add local functions (in a where clause) along with their explicit type signatures.&nbsp; Start with the inner most case expressions and convert those to local functions and work your way out.<br>
 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I&#39;ve tried adding some signatures (together with -XScopedTypeVariables), but with no luck. Why is it that this no longer compiles? More importantly, how can I make it compile again? :)</blockquote>
<div><br>I think adding local functions is easier than randomly sprinkling in the type signatures.&nbsp; It has a nice side-effect that your new code is often easier to read as well.<br> <br>Good luck!<br>Jason</div></div></div>
</blockquote><br></div></div><div>Thanks for the advice!</div><div><br></div><div>By using some auxiliary functions I can now compile an alternative version of the program. And although the resulting program is more clear, I&#39;d still like to know if this can be achieved be adding only annotations to the original program. The reason for this is that, for performance reasons, &nbsp;I depend on the case-of-case transformation removing every possible case construct. I already verified this is happening for the original program and I rather keep the code as is than browse through the generated core again :)</div>
</div></blockquote><div><br>It&#39;s unfortunate that you have such a situation with the optimizer.&nbsp; How often do you check that the optimizer is still smart enough?&nbsp; It seems like the sort of thing that could easily break between compiler releases.&nbsp; If you are going to depend on, I wonder if you could write a test to ensure that it is happening every time.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style=""><div></div><div><br></div><div>I must say that I also found this thread to be very helpful:</div>
<div><br></div><div><a href="http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/15153" target="_blank">http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/15153</a></div></div></blockquote><div><br>That is a good thread and it helped me a lot in the past too.&nbsp; One of the most important bits is when Simon says this:<br>
<pre>GHC now enforces the rule that in a GADT pattern match<br>        - the type of the scrutinee must be rigid<br>        - the result type must be rigid<br>        - the type of any variable free in the case branch must be rigid<br>
<br></pre>I would hypothesize that most people who encounter the message you&#39;re getting fall into the last case, but I may be biased by my own experiences.<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style=""><div><a href="http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/15153" target="_blank"></a></div><div><br></div><div>I&#39;ll make sure the wiki points to it.</div></div></blockquote><div><br>Oh, good idea!&nbsp; Thanks!<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style=""><div></div><div><br></div><div>For the record the resulting code is this:</div>
<div><br></div><div><div>{-# LANGUAGE GADTs, EmptyDataDecls #-}</div><div class="Ih2E3d"><div>module T where</div><div><br></div><div>data S</div><div>data M</div><div><br></div><div>data Wit t where</div><div>&nbsp;&nbsp; &nbsp;S :: Wit S</div>
<div>&nbsp;&nbsp; &nbsp;M :: Wit M</div><div><br></div><div>data Impl t a where</div><div>&nbsp;&nbsp; &nbsp;I1 :: Maybe a -&gt; Impl S a</div><div>&nbsp;&nbsp; &nbsp;I2 :: [a] &nbsp; &nbsp; -&gt; Impl M a</div><div><br></div><div>type W_ t a = Wit t -&gt; Impl t a</div><div>
<br></div><div>newtype W t a = Wrap (W_ t a)</div><div><br></div></div><div>unWrap1 :: Impl S a -&gt; Maybe a</div><div>unWrap1 (I1 m) = m</div><div><br></div><div>unWrap2 :: Impl M a -&gt; [a]</div><div>unWrap2 (I2 m) = m</div>
<div class="Ih2E3d"><div><br></div><div>bind :: W t a -&gt; (a -&gt; W t b) -&gt; W_ t b</div><div>bind (Wrap w) f = \wit -&gt;</div><div>&nbsp;&nbsp; &nbsp;case wit of</div></div><div>&nbsp;&nbsp; &nbsp; &nbsp;S -&gt; I1 $ do a &lt;- unWrap1 (w S)</div><div>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case (f a) of</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Wrap w&#39; -&gt; unWrap1 (w&#39; S)</div><div>&nbsp;&nbsp; &nbsp; &nbsp;M -&gt; I2 $ do a &lt;- unWrap2 (w M)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case (f a) of</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Wrap w&#39; -&gt; unWrap2 (w&#39; M)</div>
<div><br></div></div><div></div></div></blockquote><div><br>My (untested) hunch is that, Wrap w&#39;, needs a type signature in your original version.&nbsp; I think this because of the 3rd case I mentioned above.&nbsp; It would seem that your unWrap1 and unWrap2 fix the witness type, either S or M.&nbsp; Without playing with it (and again I don&#39;t have 6.10 handy), I&#39;m not sure which side of the arrow needs the type signature.&nbsp; It could be that you need something like:<br>
Wrap (w&#39; :: A type signature fixing M or S)<br><br>Or, you need it on the other side:<br>Wrap w&#39; -&gt; (w&#39; :: some type sig) M <br></div></div><br>Either way, I think think the type t needs to be mentioned somewhere.<br>
<br>Good luck and let me know what you figure out, I&#39;m quite curious now.<br>Jason<br></div>