insertST :: StateDecoder -> SomeState -> Update SomeState SomeThing
insertST stDecoder st = ...
the stuff in StateDecoder can't be used in
$(makeAcidic ''SomeState ['insertST])
but if I declare a state and wrap it like this ...
myDecoder :: StateDecoder
myDecoder = ...
insertSomeState :: SomeState -> Update SomeState SomeThing
insertSomeState st = insertST someDecoder
Then it works
I have a lot of datatypes that follow this pattern so I thought I would write some TH to solve it.
mkWrappedAcid :: Name -> Name -> Q [Dec]
mkWrappedAcid decoder stname = do
insP@(FunD n _) <- insertMaker decoder stname
acidP <- mkAcidic stname [n]
return $[insP] ++ acidP
insertMaker :: Name -> Name -> Q [Dec]
insertMaker decoder stname = (funD istorename) [(clause [] (normalB insertStTH ) [] )
where
istorename = mkName.concat $ ["insert" , (nameBase stname)]
insertStTH = appE (varE 'insertST ) (varE decoder)
Which all works beautifully but when I try and run...
$(mkWrappedAcid 'myDecoder ''SomeState)
I get...
`insertSomeState' is not in scope at a reify
I know it has something to do with the staging problem in template haskell but I don't know how to solve it. It works if I do
$(mkWrappedAcid 'myDecoder ''SomeState)
$(makeAcidic ''SomeState ['insertSomeState])
But that doesn't help!