On Wed, Jan 7, 2009 at 8:54 PM, Ryan Ingram <ryani.s...@gmail.com> wrote:

> You can also use $() and [| |] inside [| |] to generate additional
> data in TH directly:
>
> ghci> runQ $ do { VarE n <- [| runIdentity |] ; [| \x -> $(recUpdE [|
> x |] [ fmap (\e -> (n,e)) [| 1 |] ]) |] }
> LamE [VarP x_2] (RecUpdE (VarE x_2) [(Control.Monad.Identity.runIdentity,LitE 
> (I
> ntegerL 1))])
>
> Note the "VarE n <- [| identifier |]" trick to extract the name from
> an identifier.

You can use the single quote to get the name of a value.

ghci> runQ [| \x -> $(recUpdE [| x |] [ fmap (\e -> ('runIdentity, e))
[| 1 |] ]) |]
LamE [VarP x_1] (RecUpdE (VarE x_1)
[(Control.Monad.Identity.runIdentity,LitE (IntegerL 1))])

There's more in section 8.9.1 of the GHC manual.
-- 
Dave Menendez <d...@zednenem.com>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to