Copyright | (c) Roman Leshchinskiy 2009 |
---|---|

License | BSD-style |

Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell2010 |

Primitive state-transformer monads

- class Monad m => PrimMonad m where
- data RealWorld :: *
- primitive_ :: PrimMonad m => (State# (PrimState m) -> State# (PrimState m)) -> m ()
- primToPrim :: (PrimMonad m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a
- primToIO :: (PrimMonad m, PrimState m ~ RealWorld) => m a -> IO a
- primToST :: PrimMonad m => m a -> ST (PrimState m) a
- unsafePrimToPrim :: (PrimMonad m1, PrimMonad m2) => m1 a -> m2 a
- unsafePrimToIO :: PrimMonad m => m a -> IO a
- unsafePrimToST :: PrimMonad m => m a -> ST s a
- unsafeInlinePrim :: PrimMonad m => m a -> a
- unsafeInlineIO :: IO a -> a
- unsafeInlineST :: ST s a -> a
- touch :: PrimMonad m => a -> m ()

# Documentation

class Monad m => PrimMonad m where Source

Class of primitive state-transformer monads

data RealWorld :: *

`RealWorld`

is deeply magical. It is *primitive*, but it is not
*unlifted* (hence `ptrArg`

). We never manipulate values of type
`RealWorld`

; it's only used in the type system, to parameterise `State#`

.

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

Execute a primitive operation with no result

primToPrim :: (PrimMonad m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a Source

Convert a `PrimMonad`

to another monad with the same state token.

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

Convert a `PrimMonad`

to another monad with a possibly different state
token. This operation is highly unsafe!

unsafePrimToIO :: PrimMonad m => m a -> IO a Source

unsafePrimToST :: PrimMonad m => m a -> ST s a Source

unsafeInlinePrim :: PrimMonad m => m a -> a Source

unsafeInlineIO :: IO a -> a Source

unsafeInlineST :: ST s a -> a Source