I'm using Lucid to generate code for a static site, writing code in the HtmlT (Reader MyEnv)
monad to transparently pass around some configuration stored in MyEnv
.
The framework I'm using encapsulates the transformation from Html ()
to file output, so I'd like to write a function to transform HtmlT (Reader MyEnv) ()
to Html ()
; something like:
withEnv :: MyEnv -> HtmlT (Reader MyEnv) () -> Html ()
But I haven't yet come up with a simple way to implement this. Am I missing something fundamental, or is there a workaround?
You can use commuteHtmlT
:
commuteHtmlT :: HtmlT (Reader MyEnv) a -> Reader MyEnd (Html a)
runReader :: Reader a r -> a -> r
withEnv :: MyEnv -> HtmlT (Reader MyEnv) a -> Html a
withEnv e = ($ e) . runReader . commuteHtmlT