简体   繁体   中英

Snap, How to lift IO monade inside a SnapletISplice

I have a IO Bool function that give me some state information. I would like to write "OK" or "KO" depending of the value returned by this function into a splice of a .tpl file.

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.

I'm pretty sure the SnapletISplice "is" a IO monad, and such a lifting function should exists. But I can't figure out what is it.

Nb : I'm using snap 0.11. So some functions (like liftHandle) was removed.

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 .

HeistT implements MonadIO

So liftIO should work if it is imported

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM