Understanding bind in template haskell

Michael Sloan mgsloan at gmail.com
Mon Dec 10 05:29:31 UTC 2018


Hi Yotam,

Template Haskell expression quotes must start with either `[|` or
`[e|`, but instead these start with `[e |` - note the space. They are
list comprehensions which filter to just the elements of `es` that
match the `(dL -> L _ (Present _ e))`.  Also, the `dL -> ...` portion
is a view pattern that is equivalent to `id`, since since the
arguments are already wrapped in `L`.

For something like `runQ [| Foo b <- Foo 1 |]` to work, there'd need
to be a quotation for `Stmt`, but there are only quotations for `Exp`
/ `[Dec]` / `Type` / `Pat`.

I hope that's helpful!

-Michael


On Sat, Dec 8, 2018 at 3:30 AM Yotam Ohad <yotam2206 at gmail.com> wrote:
>
> Hi,
> In the function DsMeta.repE there is a format being repeated:
> For example in:
>
> repE e@(ExplicitTuple _ es boxed)
>   | not (all tupArgPresent es) = notHandled "Tuple sections" (ppr e)
>   | isBoxed boxed = do { xs <- repLEs [e | (dL->L _ (Present _ e)) <- es]
>                        ; repTup xs }
>   | otherwise     = do { xs <- repLEs [e | (dL->L _ (Present _ e)) <- es]
>                        ; repUnboxedTup xs }
>
> There is  `(dL->L _ (Present _ e)) <- es`. I don't understand how this type checks correctly.
> If I'll try to do
>
>  data Foo a = Foo a
> runQ [| Foo b <- Foo 1 |]
>
> in ghciI get an error. What is the difference?
>
> Yotam
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


More information about the ghc-devs mailing list