[英]Snap, How to lift IO monade inside a SnapletISplice
I have a IO Bool function that give me some state information. 我有一个IO Bool函数,它给我一些状态信息。 I would like to write "OK" or "KO" depending of the value returned by this function into a splice of a .tpl file.
我想写“OK”或“KO”,具体取决于此函数返回的值到.tpl文件的拼接中。
So what I would be happy is a way of lifting IO monads inside a SnapletISplice, so that I can just bind statusSplice :: SnapletISplice App with ("splicename", statusSplice), and compute the value from IO monad inside. 所以我很高兴能够在SnapletISplice中提升IO monads,这样我就可以将statusSplice :: SnapletISplice App与(“splicename”,statusSplice)绑定,并计算IO monad里面的值。
I'm pretty sure the SnapletISplice "is" a IO monad, and such a lifting function should exists. 我很确定SnapletISplice“是”IO monad,并且应该存在这样的提升功能。 But I can't figure out what is it.
但我无法弄清楚它是什么。
Nb : I'm using snap 0.11. Nb:我正在使用按扣0.11。 So some functions (like liftHandle) was removed.
所以删除了一些函数(如liftHandle)。
In short, with code, what I would like to do : 简而言之,使用代码,我想做什么:
app = ...
addSplices splices
...
splices = [("spliceName", statusSplice)]
statusSplice :: SnapletISplice App
statusSplice = do
st <- lift $ computeStatus
if st then textSplice "ok" else textSplice "ko"
SnapletISplice
an alias for HeistT
. SnapletISplice
一个别名HeistT
。
HeistT
implements MonadIO
HeistT
实现了MonadIO
So liftIO
should work if it is imported 所以如果导入的话,
liftIO
应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.