primitive-0.6.1.0: Primitive memory-related operations

Copyright(c) Roman Leshchinskiy 2009
LicenseBSD-style
MaintainerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Primitive

Description

Primitive state-transformer monads

Synopsis

Documentation

class Monad m => PrimMonad m where #

Class of monads which can perform primitive state-transformer actions

Minimal complete definition

primitive

Associated Types

type PrimState m #

State token type

Methods

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

Execute a primitive operation

Instances

PrimMonad IO # 

Associated Types

type PrimState (IO :: * -> *) :: * #

PrimMonad (ST s) # 

Associated Types

type PrimState (ST s :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (ST s)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ST s)), a#)) -> ST s a #

PrimMonad m => PrimMonad (MaybeT m) # 

Associated Types

type PrimState (MaybeT m :: * -> *) :: * #

Methods

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

PrimMonad m => PrimMonad (ListT m) # 

Associated Types

type PrimState (ListT m :: * -> *) :: * #

Methods

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

(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) # 

Associated Types

type PrimState (WriterT w m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (WriterT w m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (WriterT w m)), a#)) -> WriterT w m a #

(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) # 

Associated Types

type PrimState (WriterT w m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (WriterT w m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (WriterT w m)), a#)) -> WriterT w m a #

PrimMonad m => PrimMonad (StateT s m) # 

Associated Types

type PrimState (StateT s m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (StateT s m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (StateT s m)), a#)) -> StateT s m a #

PrimMonad m => PrimMonad (StateT s m) # 

Associated Types

type PrimState (StateT s m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (StateT s m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (StateT s m)), a#)) -> StateT s m a #

PrimMonad m => PrimMonad (IdentityT * m) # 

Associated Types

type PrimState (IdentityT * m :: * -> *) :: * #

PrimMonad m => PrimMonad (ExceptT e m) # 

Associated Types

type PrimState (ExceptT e m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (ExceptT e m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ExceptT e m)), a#)) -> ExceptT e m a #

(Error e, PrimMonad m) => PrimMonad (ErrorT e m) # 

Associated Types

type PrimState (ErrorT e m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (ErrorT e m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ErrorT e m)), a#)) -> ErrorT e m a #

PrimMonad m => PrimMonad (ReaderT * r m) # 

Associated Types

type PrimState (ReaderT * r m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (ReaderT * r m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ReaderT * r m)), a#)) -> ReaderT * r m a #

(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) # 

Associated Types

type PrimState (RWST r w s m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (RWST r w s m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (RWST r w s m)), a#)) -> RWST r w s m a #

(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) # 

Associated Types

type PrimState (RWST r w s m :: * -> *) :: * #

Methods

primitive :: (State# (PrimState (RWST r w s m)) -> (#VoidRep, PtrRepLifted, State# (PrimState (RWST r w s m)), a#)) -> RWST r w s m a #

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 () #

Execute a primitive operation with no result

class PrimMonad m => PrimBase m where #

Class of primitive monads for state-transformer actions.

Unlike PrimMonad, this typeclass requires that the Monad be fully expressed as a state transformer, therefore disallowing other monad transformers on top of the base IO or ST.

Minimal complete definition

internal

Methods

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

Expose the internal structure of the monad

Instances

PrimBase IO # 
PrimBase (ST s) # 

Methods

internal :: ST s a -> State# (PrimState (ST s)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ST s)), a#) #

liftPrim :: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a #

Lifts a PrimBase into another PrimMonad with the same underlying state token type.

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

Convert a PrimBase to another monad with the same state token.

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

Convert a PrimBase with a RealWorld state token to IO

primToST :: PrimBase m => m a -> ST (PrimState m) a #

Convert a PrimBase to ST

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

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

unsafePrimToIO :: PrimBase m => m a -> IO a #

Convert any PrimBase to IO. This operation is highly unsafe!

unsafePrimToST :: PrimBase m => m a -> ST s a #

Convert any PrimBase to ST with an arbitrary state token. This operation is highly unsafe!

unsafeInlinePrim :: PrimBase m => m a -> a #

unsafeInlineIO :: IO a -> a #

unsafeInlineST :: ST s a -> a #

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