Portability | portable |
---|---|

Stability | experimental |

Maintainer | Anders Kaseorg <andersk@mit.edu> |

Safe Haskell | Safe-Inferred |

This module defines the class `MonadPeelIO`

of `IO`

-based monads into
which control operations on `IO`

(such as exception catching; see
Control.Exception.Peel) can be lifted.

`liftIOOp`

and `liftIOOp_`

enable convenient lifting of two common
special cases of control operation types.

- class MonadIO m => MonadPeelIO m where
- liftIOOp :: MonadPeelIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m c
- liftIOOp_ :: MonadPeelIO m => (IO (m a) -> IO (m b)) -> m a -> m b

# Documentation

class MonadIO m => MonadPeelIO m whereSource

`MonadPeelIO`

is the class of `IO`

-based monads supporting an
extra operation `peelIO`

, enabling control operations on `IO`

to be
lifted into the monad.

peelIO :: m (m a -> IO (m a))Source

`peelIO`

is a version of `peel`

that operates through an
arbitrary stack of monad transformers directly to an inner `IO`

(analagously to how `liftIO`

is a version of `lift`

). So it can
be used with `liftIO`

to lift control operations on `IO`

into any
monad in `MonadPeelIO`

. For example:

foo ::`IO`

a ->`IO`

a foo' ::`MonadPeelIO`

m => m a -> m a foo' a = do k <-`peelIO`

-- k :: m a -> IO (m a)`join`

$`liftIO`

$ foo (k a) -- uses foo ::`IO`

(m a) ->`IO`

(m a)

Note that the "obvious" term of this type (`peelIO = `

) `return`

`return`

*does not* work correctly. Instances of `MonadPeelIO`

should be constructed via `MonadTransPeel`

, using ```
peelIO =
```

.
`liftPeel`

peelIO

MonadPeelIO IO | |

(MonadIO (MaybeT m), MonadPeelIO m) => MonadPeelIO (MaybeT m) | |

(MonadIO (ListT m), MonadPeelIO m) => MonadPeelIO (ListT m) | |

(MonadIO (IdentityT m), MonadPeelIO m) => MonadPeelIO (IdentityT m) | |

(MonadIO (WriterT w m), Monoid w, MonadPeelIO m) => MonadPeelIO (WriterT w m) | |

(MonadIO (WriterT w m), Monoid w, MonadPeelIO m) => MonadPeelIO (WriterT w m) | |

(MonadIO (StateT s m), MonadPeelIO m) => MonadPeelIO (StateT s m) | |

(MonadIO (StateT s m), MonadPeelIO m) => MonadPeelIO (StateT s m) | |

(MonadIO (ReaderT r m), MonadPeelIO m) => MonadPeelIO (ReaderT r m) | |

(MonadIO (ErrorT e m), Error e, MonadPeelIO m) => MonadPeelIO (ErrorT e m) | |

(MonadIO (RWST r w s m), Monoid w, MonadPeelIO m) => MonadPeelIO (RWST r w s m) | |

(MonadIO (RWST r w s m), Monoid w, MonadPeelIO m) => MonadPeelIO (RWST r w s m) |

liftIOOp :: MonadPeelIO m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m cSource