[Haskell-cafe] Template Haskell -- when are things evaluated?
emax at cs.chalmers.se
Thu Mar 13 05:50:57 EDT 2008
Aha, I guess I thought for a while that [|x|] and lift x where the same thing.
Having thought too much about partial evaluation lately, I forgot that the main
purpose of quoting is to get the unevaluated AST.
I'll just use lift in the future then (for partial evalutation).
On 2008-03-13 09:49, Alfonso Acosta wrote:
> 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
> 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 |]
>> 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