Safe Haskell | Trustworthy |
---|---|
Language | Haskell98 |
- data IOT m t
- run :: IOT Identity t -> IO t
- module Control.Monad.Trans
- module Control.Monad.Identity
- module Control.Monad.Morph
Documentation
An IO monad transformer.
IOT
cannot be unwrapped in the usual way -- the monad inside it
has to be unwrapped. This is done using run
, and hoist
from mmorph.
Most of the safety of the IO monad is ensured statically.
However, to ensure that the same RealWorld token is not
used multiple times, a runtime check is necessary. Among
the alternatives that perform I/O, the first alternative
forced by a concatenation of hoist
s will contain a result,
and subsequent alternatives will be errors.
Therefore, a concatenation of hoists
out of a monad defines
at most one path of RealWorld token use. Here is an example using
the binary tree monad:
>>>
let io :: IOT Tree () = lift (Node (Leaf 1) (Leaf 2)) >>= liftIO . print
>>>
run $ hoist (\(Node (Leaf x) _) -> Identity x) io
1
>>>
run $ hoist (\(Node _ (Leaf x)) -> Identity x) io
2
>>>
run $ hoist (\(Node (Leaf _) (Leaf x)) -> Identity x) io
1 *** Exception: IOT: double RealWorld use
run :: IOT Identity t -> IO t Source
Run an IOT yielding an IO computation. The Identity
monad is a trivial wrapper around IO.
module Control.Monad.Trans
module Control.Monad.Identity
module Control.Monad.Morph