[Template-haskell] Reification of top level variables - was: Re: Problem with Labelled Fields

Ian Lynagh igloo@earth.li
Fri, 27 Jun 2003 13:51:01 +0100


On Fri, Jun 27, 2003 at 11:43:21AM +0200, Eric Offermann wrote:
> 
> Thus, the possibility of using a "reifyVar c :: Q String" in the instance of
> lift c yielding the original name of c would be useful to keep the instance
> decleration generic. Any hint on implementing that?

What you could do is to pass c_succS an ExpQ instead, so:



module Main where
import SpliceC
sampleC_succ = $(c_succS [| sampleC |])




module SpliceC where

import Language.Haskell.THSyntax

data C a = C
  {c_succ :: a -> a
  ,c_pred :: a -> a
  }

c_succS :: ExpQ -> ExpQ
c_succS c = [| \ a -> c_succ $c a |]

sampleC :: C Int
sampleC = C
  {c_succ = \ n -> n + 1
  ,c_pred = \ n -> n - 1
  }



Thanks
Ian