<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><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">dgorin@dc.uba.ar</a>></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 "GADT pattern match...." error, instead :)<br> <br> Here is a boiled-down example:</blockquote></div></div></blockquote><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 class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">[...]</span></blockquote></div></div></blockquote><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div><br>I don't have 6.10 handy to try out your program, but in 6.8 and older the type error message you're getting means that the compiler needs more "outside in" 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'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'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>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'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><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">http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/15153</a></div><div><br></div><div>I'll make sure the wiki points to it.</div><div><br></div><div>For the record the resulting code is this:</div><div><br></div><div><div>{-# LANGUAGE GADTs, EmptyDataDecls #-}</div><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 -> Impl S a</div><div>&nbsp;&nbsp; &nbsp;I2 :: [a] &nbsp; &nbsp; -> Impl M a</div><div><br></div><div>type W_ t a = Wit t -> Impl t a</div><div><br></div><div>newtype W t a = Wrap (W_ t a)</div><div><br></div><div>unWrap1 :: Impl S a -> Maybe a</div><div>unWrap1 (I1 m) = m</div><div><br></div><div>unWrap2 :: Impl M a -> [a]</div><div>unWrap2 (I2 m) = m</div><div><br></div><div>bind :: W t a -> (a -> W t b) -> W_ t b</div><div>bind (Wrap w) f = \wit -></div><div>&nbsp;&nbsp; &nbsp;case wit of</div><div>&nbsp;&nbsp; &nbsp; &nbsp;S -> 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' -> unWrap1 (w' S)</div><div>&nbsp;&nbsp; &nbsp; &nbsp;M -> 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' -> unWrap2 (w' M)</div><div><br></div></div><div><br></div><div>Bye</div><div>Daniel</div><div><br></div><br></body></html>