License | BSD-style |
---|---|

Maintainer | Vincent Hanquez <vincent@snarc.org> |

Stability | experimental |

Portability | portable |

Safe Haskell | None |

Language | Haskell2010 |

Allow to run operation in ST and IO, without having to distinguinsh between the two. Most operations exposes the bare nuts and bolts of how IO and ST actually works, and relatively easy to shoot yourself in the foot

this is highly similar to the Control.Monad.Primitive in the primitive package

- class (Functor m, Applicative m, Monad m) => PrimMonad m where
- class AMPMonad m => MonadFailure m where
- type Failure m

- unPrimMonad_ :: PrimMonad m => m () -> State# (PrimState m) -> State# (PrimState m)
- unsafePrimCast :: (PrimMonad m1, PrimMonad m2) => m1 a -> m2 a
- unsafePrimToST :: PrimMonad prim => prim a -> ST s a
- unsafePrimToIO :: PrimMonad prim => prim a -> IO a
- unsafePrimFromIO :: PrimMonad prim => IO a -> prim a
- primTouch :: PrimMonad m => a -> m ()

# Documentation

class (Functor m, Applicative m, Monad m) => PrimMonad m where Source #

Primitive monad that can handle mutation.

For example: IO and ST.

type of state token associated with the PrimMonad m

type PrimVar m :: * -> * Source #

type of variable associated with the PrimMonad m

primitive :: (State# (PrimState m) -> (#State# (PrimState m), a#)) -> m a Source #

Unwrap the State# token to pass to a function a primitive function that returns an unboxed state and a value.

primThrow :: Exception e => e -> m a Source #

Throw Exception in the primitive monad

unPrimMonad :: m a -> State# (PrimState m) -> (#State# (PrimState m), a#) Source #

Run a Prim monad from a dedicated state#

primVarNew :: a -> m (PrimVar m a) Source #

Build a new variable in the Prim Monad

primVarRead :: PrimVar m a -> m a Source #

Read the variable in the Prim Monad

primVarWrite :: PrimVar m a -> a -> m () Source #

Write the variable in the Prim Monad

class AMPMonad m => MonadFailure m where Source #

Monad that can represent failure

Similar to MonadFail but with a parametrized Failure linked to the Monad

The associated type with the MonadFailure, representing what failure can be encoded in this monad

MonadFailure Maybe Source # | |

MonadFailure (Either a) Source # | |

Monad state => MonadFailure (Builder collection mutCollection step state err) Source # | |

unPrimMonad_ :: PrimMonad m => m () -> State# (PrimState m) -> State# (PrimState m) Source #

just like `unwrapPrimMonad`

but throw away the result and return just the new State#

unsafePrimCast :: (PrimMonad m1, PrimMonad m2) => m1 a -> m2 a Source #

Convert a prim monad to another prim monad.

The net effect is that it coerce the state repr to another, so the runtime representation should be the same, otherwise hilary ensues.

unsafePrimToST :: PrimMonad prim => prim a -> ST s a Source #

Convert any prim monad to an ST monad

unsafePrimToIO :: PrimMonad prim => prim a -> IO a Source #

Convert any prim monad to an IO monad

unsafePrimFromIO :: PrimMonad prim => IO a -> prim a Source #

Convert any IO monad to a prim monad