splicing varPs in quasi-quote brackets
Hello everybody, I wrote me this nice function 'buildRns' which splices in $(varP w) nice and recursively. Unfortunately, this only seems to work in the 7.8 branch, not in 7.6.3. Is this indeed new, or am I missing something obvious? The message is: ADP/Fusion/TH.hs:106:86: Parse error in pattern: $(varP w) The code works wonderfully in 7.8. It not only compiles, but also produces working code in applications. I have no problem waiting until 7.8 is stable, but being backwards compatible to 7.6 would be nice. Many thanks, Christian buildRns f xs [] = appE ([| return . SM.singleton |]) (foldl (\g z -> appE g (varE z)) (return f) xs) buildRns f xs (VarP v : ys) = buildRns f (xs++[v]) ys buildRns f xs (TupP [_,VarP v] : ys) = do w <- newName "w" [| $(varE v) >>= return . SM.concatMapM (\ $(varP w) -> $(buildRns f (xs++[w]) ys)) |] -->>>>> ^^^^^^^^^
Hello Christian, It seems new to me that $( ) is allowed in patterns. I would have used lamE in something like: [| $(varE v) >>= return . SM.concatMapM $(lamE [varP v] (buildRns f (xs++[w]) ys))) |] Regards, Adam
Thanks Adam, It indeed does work with a lambda, should've thought about it. So, it seems splices in patterns are new in 7.8 (hadn't seen it in the notes). Gruss, Christian * adam vogt <vogt.adam@gmail.com> [15.03.2014 05:12]:
Hello Christian,
It seems new to me that $( ) is allowed in patterns. I would have used lamE in something like:
[| $(varE v) >>= return . SM.concatMapM $(lamE [varP v] (buildRns f (xs++[w]) ys))) |]
Regards, Adam
Yes, pattern splices are indeed new in 7.8. See: https://www.cs.drexel.edu/~mainland/2013/05/31/type-safe-runtime-code-genera... Cheers, Geoff On 03/15/2014 10:08 AM, Christian Höner zu Siederdissen wrote:
Thanks Adam,
It indeed does work with a lambda, should've thought about it. So, it seems splices in patterns are new in 7.8 (hadn't seen it in the notes).
Gruss, Christian
* adam vogt <vogt.adam@gmail.com> [15.03.2014 05:12]:
Hello Christian,
It seems new to me that $( ) is allowed in patterns. I would have used lamE in something like:
[| $(varE v) >>= return . SM.concatMapM $(lamE [varP v] (buildRns f (xs++[w]) ys))) |]
Regards, Adam
Geoffrey This major new feature of Template Haskell is barely reflected in the user manual at all, except a cryptic reference to "a typed expression splice". Might it be possible to add a summary; such as the very fact that there are now two pretty separate parts of TH: the untyped part and the typed part. Plus some links to your blog posts, the TH blog post that described the change? Are there any other relevant links? Simon | -----Original Message----- | From: Glasgow-haskell-users [mailto:glasgow-haskell-users- | bounces@haskell.org] On Behalf Of Geoffrey Mainland | Sent: 15 March 2014 14:45 | To: glasgow-haskell-users@haskell.org | Subject: Re: splicing varPs in quasi-quote brackets | | Yes, pattern splices are indeed new in 7.8. See: | | https://www.cs.drexel.edu/~mainland/2013/05/31/type-safe-runtime-code- | generation-with-typed-template-haskell/ | | Cheers, | Geoff | | On 03/15/2014 10:08 AM, Christian Höner zu Siederdissen wrote: | > Thanks Adam, | > | > It indeed does work with a lambda, should've thought about it. So, it | > seems splices in patterns are new in 7.8 (hadn't seen it in the | notes). | > | > Gruss, | > Christian | > | > * adam vogt <vogt.adam@gmail.com> [15.03.2014 05:12]: | >> Hello Christian, | >> | >> It seems new to me that $( ) is allowed in patterns. I would have | >> used lamE in something like: | >> | >> [| $(varE v) >>= return . SM.concatMapM $(lamE [varP v] (buildRns f | >> (xs++[w]) ys))) |] | >> | >> Regards, | >> Adam | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (4)
-
adam vogt -
Christian Höner zu Siederdissen -
Geoffrey Mainland -
Simon Peyton Jones