I'm trying to write a page handler that dumps the application's config file to a web page.
I understand that the config file should be stored in myapp/snaplet.cfg
My function is currently:
renderConfigDump :: Html
renderConfigDump = htmlTemplate False $ do
c <- getSnapletUserConfig
H.h1 "Configuration"
H.p $ show c
dumpConfigHandler :: AppHandler ()
dumpConfigHandler = do
c <- renderConfigDump
blaze c
and the error I get is:
No instance for (Monad (m0 b0 v0))
arising from a use of `getSnapletUserConfig'
Is the fix just a matter of fiddling with the type signature of renderConfigDump (and if so what should it be)
or do I have some deeper conceptual problem with how getSnapletUserConfig should be used?
I expect the latter. I suspect that Config may not have a Show instance but that bit I can probably solve if I can somehow get unstuck from the Snap monad.
Kevin
You could also do it the other way and change the type signature to
renderConfigDump :: AppHandler Html and then change it accordingly.
renderConfigDump :: AppHandler Html
gives me the same type error.
I'll try to restructure my code so that getSnapletUserConfig is called in dumpConfigHandler instead.
Kevin
import qualified Data.Text as DT
import qualified Data.Configurator as DC
renderConfigDump :: String -> Html
renderConfigDump c = htmlTemplate False $ do
H.h1 "Configuration"
H.p $ toHtml (c :: String)
dumpConfigHandler :: AppHandler ()
dumpConfigHandler = do
c <- getSnapletUserConfig
s <- liftIO $ DC.getMap c
blaze $ renderConfigDump $ show s
As is usual in Haskell, everything works if you know where to call the functions you need and throw in the occasional lift.
It turns out that the config structure not only contains all values for the top level application configuration but also for all the nested snaplets with qualified keys for the nested snaplets. Eg., if a nested snaplet is mynestedsnaplet then the top level config will also contain values for mynestedsnaplet.key1, mynestedsnaplet.key2 etc.
Very convenient!