Yesod's shakespearean templates (hamlet) and IO

痞子三分冷 提交于 2019-12-20 02:28:32

问题


In Hamlet, how does one uses the result of an IO operation inside #{...} ?

For instance :

someIO :: IO String
-----------------

$with stuff <- someIO
    <p>#{stuff}

Fails with

No instance for (blaze-markup-0.6.0.0:Text.Blaze.ToMarkup
                       (IO String))
      arising from a use of `toHtml'

I fear that I have not approached the problem from the right angle, could someone shed some light on this issue for me?

Thank you


回答1:


Hamlet is just providing an alternate syntax for normal Haskell code, so like normal Haskell, you have to keep your impure actions separate. In other words, you need to run the IO action outside of the template.



来源:https://stackoverflow.com/questions/23318426/yesods-shakespearean-templates-hamlet-and-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!