[Haskell-cafe] Template Haskell -- when are things evaluated?

Emil Axelsson emax at cs.chalmers.se
Thu Mar 13 06:13:58 EDT 2008


I'm reading the following rule from your answer:

[|exp|] normally returns the unevaluated AST of exp. However, if exp contains 
local variables, these are lifted using Language.Haskell.TH.lift (i.e. evaluated 
before lifting).

Is that correct?

/ Emil



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
> 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