Why are nested brackets disallowed?
matthewtpickering at gmail.com
Wed Jan 30 15:42:22 UTC 2019
I put up a patch which removes this restriction (for untyped expressions).
On Thu, Jan 24, 2019 at 11:46 AM Matthew Pickering
<matthewtpickering at gmail.com> wrote:
> There is a check in `RnSplice` which errors on the following program
> with nested brackets.
> prog = [| [| True |] |]
> T.hs:4:11: error:
> • Template Haskell brackets cannot be nested (without intervening splices)
> • In the Template Haskell quotation [| True |]
> In the Template Haskell quotation [| [| True |] |]
> 4 | prog = [| [| True |] |]
> | ^^^^^^^^^^
> As far as I can see the check was added in 2013 in this commit,
> But there is no note, no tests and no comment about why it was added.
> I removed the check and added a `BracketE` constructor to the
> template-haskell AST and the
> code compiles fine.
> I can also construct a program which needs to be spliced twice and
> this also works fine.
> func Add = [| (+) |]
> func Mul = [| (*) |]
> f1 "+" = [| Add |]
> f1 "*" = [| Mul |]
> comb s = [| func $(f1 s) |]
> res = $($(comb "*"))
> So it seems the restriction is quite arbitrary but I was wondering if
> I was missing some limitation which meant this check was added. I
> would not be surprised if something more complicated goes wrong with
More information about the ghc-devs