[Haskell-cafe] Template Haskell -- when are things evaluated?
Alfonso Acosta
alfonso.acosta at gmail.com
Thu Mar 13 04:49:17 EDT 2008
Hi Emil,
Your problem is related to "how are things evaluated" not "when". The
short answer is: if you want to make sure an expression is evaluated
before you lift it, don't use quasiquotes, call
Language.Haskell.TH.lift
On Thu, Mar 13, 2008 at 9:00 AM, Emil Axelsson <emax at cs.chalmers.se> wrote:
> a1 = [| (2::Int) + 2 |]
You are lifting the expression AST, not its evaluation. a1 = lift
((2::Int) + 2) would work as you want.
> a2 = let x = (2::Int) + 2 in [| x |]
here you are enclosing a local variable in quasiquotes and, thus, [| x
|] is equivalent to "lift x"
> a3 = [| y |]
> where
> y = (2::Int) + 2
Same as in a2, y is local. Therefore [| y |] is equivalent to "lift y"
> z = (2::Int) + 2
>
> a4 = [| z |]
z is a global variable and [| z |] is lifted to a variable expression
(i.e. a4 is equivalent to "varE 'z" )
More information about the Haskell-Cafe
mailing list