Reification of top level variables - was: Re: Problem with Labelled Fields
What you will actually get is the code for applying "c_succ" to lift c (it is lifted as it is an argument to the function). However, lifting c needs to use this instance again so loops.
Ian
Ian, thanks a lot for pointing that out. This leads me to the following modification: {- spliceC.hs -} module spliceC where import Language.Haskell.THSyntax data C a = C {c_succ :: a -> a ,c_pred :: a -> a } instance Lift (C a) where lift c = recCon "C" [fieldExp "c_succ" [| c_succ $(var "sampleC") |] ,fieldExp "c_pred" [| c_pred $(var "sampleC") |] ] c_succS :: C a -> ExpQ c_succS c = [| \ a -> c_succ c a |] sampleC :: C Int sampleC = C {c_succ = \ n -> n + 1 ,c_pred = \ n -> n - 1 } 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? Thanks, Eric -- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
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
participants (2)
-
Eric Offermann -
Ian Lynagh