Problem with Labelled Fields
Hi! Perhaps there's anybody out there who can help me with the following problem with labelled fields (using ghc 6.0). The easy example modules are: {- 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 c |] ,fieldExp "c_pred" [| c_pred c |] ] 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 } {- main.hs -} module Main where import spliceC sampleC_succ = $(c_succS sampleC) I suppose that this should bring a function sampleC_succ into scope, instantiated for sampleC. But in fact I get *** Exception: stack overflow Who's wrong? Thanks, Eric
On Thu, Jun 26, 2003 at 01:15:28PM +0200, Eric Offermann wrote:
instance Lift (C a) where lift c = recCon "C" [fieldExp "c_succ" [| c_succ c |] ,fieldExp "c_pred" [| c_pred c |] ]
I think [| c_succ c |] doesn't do what you think it does - are you hoping for it to be the code for "\n -> n + 1"? 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
participants (2)
-
Eric Offermann -
Ian Lynagh