Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to integrate Acid-State's Template Haskell into your own template haskell
    primarykey
    data
    text
    <p>I'm writing a template haskell library for my own use that generates functions. What I would like to do is pass these generated functions to acid-state's makeAcidic TH function. </p> <p>However, the result of simply passing the generated name in my Q context results in this error:</p> <p>is not in scope at a reify</p> <p>How do I put my freshly created functions in scope for makeAcidic to work?</p> <p>My code:</p> <pre><code>gen_render :: Name -&gt; Q [Dec] gen_render typName = do (TyConI d) &lt;- reify typName -- Get all the information on the type (type_name, vars, nars, constructors) &lt;- typeInfo (return d) -- extract name and constructors x &lt;- mapM func_def constructors let funcs = concat x let setterNames = [setter | (setter, _) &lt;- funcs] acidic &lt;- makeAcidic typName setterNames return $ [newFuncs | (_, newFuncs) &lt;- funcs] ++ acidic where func_def data_con@(con_name, compontents) = do x &lt;- mapM genFieldSetandGet compontents return $ concat x genFieldSetandGet (Just fieldName, fieldType) = do uVar &lt;- runQ $ varE $ mkName "u" ixInsert &lt;- appsE $ [[| IxSet.insert |], (varE $ mkName "u"), parensE $ appsE [(varE fieldName), (varE $ mkName "db")]] {-instanceD (cxt []) (conT (mkName "DatabaseAccess") `appT` (return fieldType) `appT` conT typName)-} let setterName = (mkName $ "updateDb" ++ (capitalize $ nameBase fieldName)) func &lt;- funD setterName $ [clause [(varP $ mkName "u"), (varP $ mkName "db")] (normalB $ [| modify |] `appE` [| IxSet.insert |] `appE` (varE $ mkName "u") ) []] return [(setterName, func)] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload