本文介绍了Yesod的莎士比亚模板(哈姆雷特)和IO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hamlet中,如何在#{...} 中使用IO操作的结果?

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

For instance :

不符合

Fails with 

我担心我没有从正确的角度来处理这个问题,有人能为我解释这个问题吗?

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

谢谢

推荐答案

哈姆雷特正在为正常的哈斯克尔代码提供一种替代语法,与普通的哈斯克尔一样,你必须将不纯的动作分开。换句话说,您需要在模板之外运行IO操作。

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.

这篇关于Yesod的莎士比亚模板(哈姆雷特)和IO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:30