
Hi, Simon Thanks a lot for your mail. It turns out I could have resolved this by myself (with the help of this thread http://thread.gmane.org/gmane.comp.lang.haskell.glasgow.user/15153 , to be honest). What I was missing was this key part:
bind :: forall a b t. W t a -> (a -> W t b) -> W_ t b ------- the forall brings a,b,t into scope inside bind
So, while I had turned on the ScopedTypeVariables extension, none of the type variables in question was actually in scope. How embarrassing! I can't blame anyone but me for this but, anyway, I feel that it may have helped me if the introduction of Section 8.7.6 of the user manual were a little more explicit about this. Although the example reads "f :: forall a. [a] -> [a]", and the text below says "The type signature for f brings the type variable into scope", the role of the "forall" is not mentioned until Section 8.7.6.2 (and since I already knew what the extension was about, and was only looking for the proper extension name, I didn't make it that far :)) Also, since you are always willing to get examples of confusing error messages, I wanted to bring this one into attention:
In your case the error message was:
GADT.hs:26:56: GADT pattern match with non-rigid result type `Maybe a' Solution: add a type signature In a case alternative: I1 m' -> m' In the expression: case w' S of { I1 m' -> m' } In a case alternative: Wrap w' -> case w' S of { I1 m' -> m' }
This is when ScopedTypeVariables is off. Now, what I found very confusing at first is that I thought the "a" in 'Maybe a' was referring to the "a" in 'W t a -> (a -> W t b) -> W_ t b', and I couldn't see how that could be happening. Once ScopedTypeVariables is on, one gets 'GADT pattern match with non-rigid result type `Maybe a1'" and everything makes more sense :) And maybe the "add a type signature" can be more explicit? Like "add a type signature that makes the type of the result known at the matching point". Just a suggestion...
I hope this helps. I'm still trying to find a really good way to explain the reasoning here. Do pls augment the wiki page with what you have learned!
I've put some of this in the "Upgrading packages" wiki, and added a link to the previous thread which I found to be very clear. Thanks again! Daniel