Search code examples
haskelliosplicehaskell-snap-framework

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"

Solution

  • SnapletISplice an alias for HeistT.

    HeistT implements MonadIO

    So liftIO should work if it is imported