Control.Monad.Primitive

primitive-0.3.1: Wrappers for primitive operations

Portability | non-portable
Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au>

Control.Monad.Primitive

Description

Primitive state-transformer monads

Synopsis

- class Monad m => PrimMonad m where
  - type PrimState m
  - primitive :: (State# (PrimState m) -> (#State# (PrimState m), a#)) -> m a
  - internal :: m a -> State# (PrimState m) -> (#State# (PrimState m), a#)
- 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

Class of primitive state-transformer monads

Associated Types

type PrimState m

State token type

Methods

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

Execute a primitive operation

internal :: m a -> State# (PrimState m) -> (#State# (PrimState m), a#)

Expose the internal structure of the monad

Instances

PrimMonad IO |
PrimMonad (ST s) |

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#`.

Instances

Typeable RealWorld |

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

Execute a primitive operation with no result

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

Convert a `PrimMonad` to another monad with the same state token.

primToIO :: (PrimMonad m, PrimState m ~ RealWorld) => m a -> IO a

Convert a `PrimMonad` with a `RealWorld` state token to `IO`

primToST :: PrimMonad m => m a -> ST (PrimState m) a

Convert a `PrimMonad` to `ST`

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

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

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

Convert any `PrimMonad` to `IO`. This operation is highly unsafe!

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

Convert any `PrimMonad` to `ST` with an arbitrary state token. This operations is highly unsafe!

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

unsafeInlineIO :: IO a -> a

unsafeInlineST :: ST s a -> a

touch :: PrimMonad m => a -> m ()