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.
Synopsis
- class Monad m => PrimMonad (m :: Type -> Type) where
- data RealWorld
- primitive_ :: PrimMonad m => (State# (PrimState m) -> State# (PrimState m)) -> m ()
- class PrimMonad m => PrimBase (m :: Type -> Type) where
- class (PrimMonad m, s ~ PrimState m) => MonadPrim s (m :: Type -> Type)
- class (PrimBase m, MonadPrim s m) => MonadPrimBase s (m :: Type -> Type)
- liftPrim :: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a
- primToPrim :: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a
- primToIO :: (PrimBase m, PrimState m ~ RealWorld) => m a -> IO a
- primToST :: PrimBase m => m a -> ST (PrimState m) a
- ioToPrim :: (PrimMonad m, PrimState m ~ RealWorld) => IO a -> m a
- stToPrim :: PrimMonad m => ST (PrimState m) a -> m a
- unsafePrimToPrim :: (PrimBase m1, PrimMonad m2) => m1 a -> m2 a
- unsafePrimToIO :: PrimBase m => m a -> IO a
- unsafePrimToST :: PrimBase m => m a -> ST s a
- unsafeIOToPrim :: PrimMonad m => IO a -> m a
- unsafeSTToPrim :: PrimMonad m => ST s a -> m a
- unsafeInlinePrim :: PrimBase m => m a -> a
- unsafeInlineIO :: IO a -> a
- unsafeInlineST :: ST s a -> a
- touch :: PrimMonad m => a -> m ()
- touchUnlifted :: forall m (a :: UnliftedType). PrimMonad m => a -> m ()
- keepAlive :: PrimBase m => a -> m r -> m r
- keepAliveUnlifted :: forall m (a :: UnliftedType) r. PrimBase m => a -> m r -> m r
- evalPrim :: forall a m. PrimMonad m => a -> m a
- unsafeInterleave :: PrimBase m => m a -> m a
- unsafeDupableInterleave :: PrimBase m => m a -> m a
- noDuplicate :: PrimMonad m => m ()
Documentation
class Monad m => PrimMonad (m :: Type -> Type) where Source #
Class of monads which can perform primitive state-transformer actions.
primitive :: (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a Source #
Execute a primitive operation.
Instances
PrimMonad IO Source # | |
PrimMonad (ST s) Source # | |
PrimMonad (ST s) Source # | |
PrimMonad m => PrimMonad (MaybeT m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (AccumT w m) Source # | Since: 0.6.3.0 |
PrimMonad m => PrimMonad (ExceptT e m) Source # | |
PrimMonad m => PrimMonad (IdentityT m) Source # | |
PrimMonad m => PrimMonad (ReaderT r m) Source # | |
PrimMonad m => PrimMonad (SelectT r m) Source # | |
PrimMonad m => PrimMonad (StateT s m) Source # | |
PrimMonad m => PrimMonad (StateT s m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (WriterT w m) Source # | |
PrimMonad m => PrimMonad (ContT r m) Source # | Since: 0.6.3.0 |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) Source # | |
(Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) Source # | |
primitive_ :: PrimMonad m => (State# (PrimState m) -> State# (PrimState m)) -> m () Source #
Execute a primitive operation with no result.
class PrimMonad m => PrimBase (m :: Type -> Type) where Source #
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
.
Since: 0.6.0.0
internal :: m a -> State# (PrimState m) -> (# State# (PrimState m), a #) Source #
Expose the internal structure of the monad.
class (PrimMonad m, s ~ PrimState m) => MonadPrim s (m :: Type -> Type) Source #
class (PrimBase m, MonadPrim s m) => MonadPrimBase s (m :: Type -> Type) Source #
PrimBase'
s state token type can be annoying to handle
in constraints. This typeclass lets users (visually) notice
PrimState
equality constraints less, by witnessing that
s ~
.PrimState
m
Instances
(PrimBase m, MonadPrim s m) => MonadPrimBase s m Source # | |
Defined in Control.Monad.Primitive |
primToPrim :: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a Source #
Convert a PrimBase
to another monad with the same state token.
unsafePrimToPrim :: (PrimBase m1, PrimMonad m2) => m1 a -> m2 a Source #
Convert a PrimBase
to another monad with a possibly different state
token. This operation is highly unsafe!
unsafePrimToIO :: PrimBase m => m a -> IO a Source #
unsafePrimToST :: PrimBase m => m a -> ST s a Source #
unsafeIOToPrim :: PrimMonad m => IO a -> m a Source #
unsafeSTToPrim :: PrimMonad m => ST s a -> m a Source #
unsafeInlinePrim :: PrimBase m => m a -> a Source #
See unsafeInlineIO
. This function is not recommended for the same
reasons.
unsafeInlineIO :: IO a -> a Source #
Generally, do not use this function. It is the same as
accursedUnutterablePerformIO
from bytestring
and is well behaved under
narrow conditions. See the documentation of that function to get an idea
of when this is sound. In most cases GHC.IO.Unsafe.unsafeDupablePerformIO
should be preferred.
unsafeInlineST :: ST s a -> a Source #
See unsafeInlineIO
. This function is not recommended for the same
reasons. Prefer runST
when s
is free.
touch :: PrimMonad m => a -> m () Source #
Ensure that the value is considered alive by the garbage collection.
Warning: GHC has optimization passes that can erase touch
if it is
certain that an exception is thrown afterward. Prefer keepAlive
.
touchUnlifted :: forall m (a :: UnliftedType). PrimMonad m => a -> m () Source #
Variant of touch
that keeps a value of an unlifted type
(e.g. MutableByteArray#
) alive.
:: PrimBase m | |
=> a | Value |
-> m r | Computation |
-> m r |
Keep value x
alive until computation k
completes.
Warning: This primop exists for completeness, but it is difficult to use
correctly. Prefer keepAliveUnlifted
if the value to keep alive is simply
a wrapper around an unlifted type (e.g. ByteArray
).
keepAliveUnlifted :: forall m (a :: UnliftedType) r. PrimBase m => a -> m r -> m r Source #
Variant of keepAlive
in which the value kept alive is of an unlifted
boxed type.
evalPrim :: forall a m. PrimMonad m => a -> m a Source #
Create an action to force a value; generalizes evaluate
Since: 0.6.2.0
unsafeInterleave :: PrimBase m => m a -> m a Source #
unsafeDupableInterleave :: PrimBase m => m a -> m a Source #
noDuplicate :: PrimMonad m => m () Source #