RE: "contexts differ in length" fires when using splices in non-recursive bindings?
Simon Peyton-Jones <[email protected]> Fri, 18 Jul 2008 22:09:21 +0100
| Newsgroups | gmane.comp.lang.haskell.template |
|---|---|
| Message-ID | <638ABD0A29C8884A91BC5FB5C349B1C32AE7599230@EA-EXMSG-C334.europe.corp.microsoft.com> |
Ian has this exactly right. Yes, it is confusing, but because splices are = run (and must be run) during typechecking, I don't see a reasonably easy wa= y to fix it. A radical version would be: do a complete pass of the typechecker to run an= y splices; then re-dependency analyse the whole program; then do another co= mplete typechecker pass. But I'm reluctant to do this. Meanwhile, as Claus says -XRelaxedPolyRec will help a lot. Simon | -----Original Message----- | From: [email protected] [mailto:template-haskell- | [email protected]] On Behalf Of Ian Lynagh | Sent: 12 July 2008 12:34 | To: [email protected] | Subject: Re: [Template-haskell] "contexts differ in length" fires when us= ing | splices in non-recursive bindings? | | On Sat, Jul 12, 2008 at 12:50:50AM +0100, Claus Reinke wrote: | > | > The symptom appears in the following module, when I replace | > the native 'return's with the spliced ones: | > | > {-# LANGUAGE TemplateHaskell #-} | > import TH | > | > y :: Monad m =3D> a -> m a | > y a =3D return a | > -- $(monad [| a |]) | > | > x :: (Monad m,Eq a) =3D> m a | > x =3D return undefined | > -- $(monad [| undefined |]) | > | > There is no recursion, at least no intended one | | I think the problem is that the SCC analysis is done before the splices | are run (which is during type checking), so GHC doesn't know that you | haven't written something like | | {-# LANGUAGE TemplateHaskell #-} | module Main where | | main =3D putStrLn $ take 10 x | | y :: String | y =3D $( [| 'b':x |] ) | | x :: String | x =3D $( [| 'a':y |] ) | | in which the functions /are/ recursive. | | If you put | | $( [d| |] ) | | between the two definitions then that forces GHC to consider them as | separate binding groups (as it type checks the first binding, then runs | the splice, then type checks the second one). | | | Thanks | Ian | | _______________________________________________ | template-haskell mailing list | [email protected] | http://www.haskell.org/mailman/listinfo/template-haskell