{-# LANGUAGE CPP, MagicHash, UnboxedTuples, TypeFamilies #-}
{-# LANGUAGE FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
#if __GLASGOW_HASKELL__ < 806
{-# LANGUAGE TypeInType #-}
#endif
{-# OPTIONS_GHC -fno-warn-deprecations #-}
module Control.Monad.Primitive (
PrimMonad(..), RealWorld, primitive_,
PrimBase(..),
MonadPrim,
MonadPrimBase,
liftPrim, primToPrim, primToIO, primToST, ioToPrim, stToPrim,
unsafePrimToPrim, unsafePrimToIO, unsafePrimToST, unsafeIOToPrim,
unsafeSTToPrim, unsafeInlinePrim, unsafeInlineIO, unsafeInlineST,
touch, touchUnlifted,
keepAlive, keepAliveUnlifted,
evalPrim, unsafeInterleave, unsafeDupableInterleave, noDuplicate
) where
import Data.Kind (Type)
import GHC.Exts ( State#, RealWorld, noDuplicate#, touch#
, unsafeCoerce#, realWorld#, seq# )
import Data.Primitive.Internal.Operations (UnliftedType)
#if defined(HAVE_KEEPALIVE)
import Data.Primitive.Internal.Operations (keepAliveLiftedLifted#,keepAliveUnliftedLifted#)
#endif
import GHC.IO ( IO(..) )
import GHC.ST ( ST(..) )
#if __GLASGOW_HASKELL__ >= 802
import qualified Control.Monad.ST.Lazy as L
#endif
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont ( ContT )
import Control.Monad.Trans.Identity ( IdentityT (IdentityT) )
import Control.Monad.Trans.Maybe ( MaybeT )
import Control.Monad.Trans.Reader ( ReaderT )
import Control.Monad.Trans.State ( StateT )
import Control.Monad.Trans.Writer ( WriterT )
import Control.Monad.Trans.RWS ( RWST )
#if !MIN_VERSION_transformers(0,6,0)
import Control.Monad.Trans.List ( ListT )
import Control.Monad.Trans.Error ( ErrorT, Error)
#endif
import Control.Monad.Trans.Except ( ExceptT )
#if MIN_VERSION_transformers(0,5,3)
import Control.Monad.Trans.Accum ( AccumT )
import Control.Monad.Trans.Select ( SelectT )
#endif
#if MIN_VERSION_transformers(0,5,6)
import qualified Control.Monad.Trans.Writer.CPS as CPS
import qualified Control.Monad.Trans.RWS.CPS as CPS
#endif
import qualified Control.Monad.Trans.RWS.Strict as Strict ( RWST )
import qualified Control.Monad.Trans.State.Strict as Strict ( StateT )
import qualified Control.Monad.Trans.Writer.Strict as Strict ( WriterT )
class Monad m => PrimMonad m where
type PrimState m
primitive :: (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
class PrimMonad m => PrimBase m where
internal :: m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
primitive_ :: PrimMonad m
=> (State# (PrimState m) -> State# (PrimState m)) -> m ()
{-# INLINE primitive_ #-}
primitive_ :: forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ State# (PrimState m) -> State# (PrimState m)
f = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (\State# (PrimState m)
s# ->
case State# (PrimState m) -> State# (PrimState m)
f State# (PrimState m)
s# of
State# (PrimState m)
s'# -> (# State# (PrimState m)
s'#, () #))
instance PrimMonad IO where
type PrimState IO = RealWorld
primitive :: forall a.
(State# (PrimState IO) -> (# State# (PrimState IO), a #)) -> IO a
primitive = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO
{-# INLINE primitive #-}
instance PrimBase IO where
internal :: forall a.
IO a -> State# (PrimState IO) -> (# State# (PrimState IO), a #)
internal (IO State# RealWorld -> (# State# RealWorld, a #)
p) = State# RealWorld -> (# State# RealWorld, a #)
p
{-# INLINE internal #-}
instance PrimMonad m => PrimMonad (ContT r m) where
type PrimState (ContT r m) = PrimState m
primitive :: forall a.
(State# (PrimState (ContT r m))
-> (# State# (PrimState (ContT r m)), a #))
-> ContT r m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimMonad m => PrimMonad (IdentityT m) where
type PrimState (IdentityT m) = PrimState m
primitive :: forall a.
(State# (PrimState (IdentityT m))
-> (# State# (PrimState (IdentityT m)), a #))
-> IdentityT m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimBase m => PrimBase (IdentityT m) where
internal :: forall a.
IdentityT m a
-> State# (PrimState (IdentityT m))
-> (# State# (PrimState (IdentityT m)), a #)
internal (IdentityT m a
m) = forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m a
m
{-# INLINE internal #-}
#if !MIN_VERSION_transformers(0,6,0)
instance PrimMonad m => PrimMonad (ListT m) where
type PrimState (ListT m) = PrimState m
primitive :: forall a.
(State# (PrimState (ListT m))
-> (# State# (PrimState (ListT m)), a #))
-> ListT m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance (Error e, PrimMonad m) => PrimMonad (ErrorT e m) where
type PrimState (ErrorT e m) = PrimState m
primitive :: forall a.
(State# (PrimState (ErrorT e m))
-> (# State# (PrimState (ErrorT e m)), a #))
-> ErrorT e m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#endif
instance PrimMonad m => PrimMonad (MaybeT m) where
type PrimState (MaybeT m) = PrimState m
primitive :: forall a.
(State# (PrimState (MaybeT m))
-> (# State# (PrimState (MaybeT m)), a #))
-> MaybeT m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimMonad m => PrimMonad (ReaderT r m) where
type PrimState (ReaderT r m) = PrimState m
primitive :: forall a.
(State# (PrimState (ReaderT r m))
-> (# State# (PrimState (ReaderT r m)), a #))
-> ReaderT r m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimMonad m => PrimMonad (StateT s m) where
type PrimState (StateT s m) = PrimState m
primitive :: forall a.
(State# (PrimState (StateT s m))
-> (# State# (PrimState (StateT s m)), a #))
-> StateT s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance (Monoid w, PrimMonad m) => PrimMonad (WriterT w m) where
type PrimState (WriterT w m) = PrimState m
primitive :: forall a.
(State# (PrimState (WriterT w m))
-> (# State# (PrimState (WriterT w m)), a #))
-> WriterT w m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#if MIN_VERSION_transformers(0,5,6)
instance (Monoid w, PrimMonad m) => PrimMonad (CPS.WriterT w m) where
type PrimState (CPS.WriterT w m) = PrimState m
primitive :: forall a.
(State# (PrimState (WriterT w m))
-> (# State# (PrimState (WriterT w m)), a #))
-> WriterT w m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#endif
instance (Monoid w, PrimMonad m) => PrimMonad (RWST r w s m) where
type PrimState (RWST r w s m) = PrimState m
primitive :: forall a.
(State# (PrimState (RWST r w s m))
-> (# State# (PrimState (RWST r w s m)), a #))
-> RWST r w s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#if MIN_VERSION_transformers(0,5,6)
instance (Monoid w, PrimMonad m) => PrimMonad (CPS.RWST r w s m) where
type PrimState (CPS.RWST r w s m) = PrimState m
primitive :: forall a.
(State# (PrimState (RWST r w s m))
-> (# State# (PrimState (RWST r w s m)), a #))
-> RWST r w s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#endif
instance PrimMonad m => PrimMonad (ExceptT e m) where
type PrimState (ExceptT e m) = PrimState m
primitive :: forall a.
(State# (PrimState (ExceptT e m))
-> (# State# (PrimState (ExceptT e m)), a #))
-> ExceptT e m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#if MIN_VERSION_transformers(0,5,3)
instance ( Monoid w
, PrimMonad m
) => PrimMonad (AccumT w m) where
type PrimState (AccumT w m) = PrimState m
primitive :: forall a.
(State# (PrimState (AccumT w m))
-> (# State# (PrimState (AccumT w m)), a #))
-> AccumT w m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimMonad m => PrimMonad (SelectT r m) where
type PrimState (SelectT r m) = PrimState m
primitive :: forall a.
(State# (PrimState (SelectT r m))
-> (# State# (PrimState (SelectT r m)), a #))
-> SelectT r m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
#endif
instance PrimMonad m => PrimMonad (Strict.StateT s m) where
type PrimState (Strict.StateT s m) = PrimState m
primitive :: forall a.
(State# (PrimState (StateT s m))
-> (# State# (PrimState (StateT s m)), a #))
-> StateT s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance (Monoid w, PrimMonad m) => PrimMonad (Strict.WriterT w m) where
type PrimState (Strict.WriterT w m) = PrimState m
primitive :: forall a.
(State# (PrimState (WriterT w m))
-> (# State# (PrimState (WriterT w m)), a #))
-> WriterT w m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance (Monoid w, PrimMonad m) => PrimMonad (Strict.RWST r w s m) where
type PrimState (Strict.RWST r w s m) = PrimState m
primitive :: forall a.
(State# (PrimState (RWST r w s m))
-> (# State# (PrimState (RWST r w s m)), a #))
-> RWST r w s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimMonad (ST s) where
type PrimState (ST s) = s
primitive :: forall a.
(State# (PrimState (ST s)) -> (# State# (PrimState (ST s)), a #))
-> ST s a
primitive = forall s a. STRep s a -> ST s a
ST
{-# INLINE primitive #-}
instance PrimBase (ST s) where
internal :: forall a.
ST s a
-> State# (PrimState (ST s)) -> (# State# (PrimState (ST s)), a #)
internal (ST STRep s a
p) = STRep s a
p
{-# INLINE internal #-}
#if __GLASGOW_HASKELL__ >= 802
instance PrimMonad (L.ST s) where
type PrimState (L.ST s) = s
primitive :: forall a.
(State# (PrimState (ST s)) -> (# State# (PrimState (ST s)), a #))
-> ST s a
primitive = forall s a. ST s a -> ST s a
L.strictToLazyST forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
{-# INLINE primitive #-}
instance PrimBase (L.ST s) where
internal :: forall a.
ST s a
-> State# (PrimState (ST s)) -> (# State# (PrimState (ST s)), a #)
internal = forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. ST s a -> ST s a
L.lazyToStrictST
{-# INLINE internal #-}
#endif
class (PrimMonad m, s ~ PrimState m) => MonadPrim s m
instance (PrimMonad m, s ~ PrimState m) => MonadPrim s m
class (PrimBase m, MonadPrim s m) => MonadPrimBase s m
instance (PrimBase m, MonadPrim s m) => MonadPrimBase s m
liftPrim
:: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) => m1 a -> m2 a
{-# INLINE liftPrim #-}
liftPrim :: forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
liftPrim = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
primToPrim :: (PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2)
=> m1 a -> m2 a
{-# INLINE primToPrim #-}
primToPrim :: forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim m1 a
m = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m1 a
m)
primToIO :: (PrimBase m, PrimState m ~ RealWorld) => m a -> IO a
{-# INLINE primToIO #-}
primToIO :: forall (m :: * -> *) a.
(PrimBase m, PrimState m ~ RealWorld) =>
m a -> IO a
primToIO = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
primToST :: PrimBase m => m a -> ST (PrimState m) a
{-# INLINE primToST #-}
primToST :: forall (m :: * -> *) a. PrimBase m => m a -> ST (PrimState m) a
primToST = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
ioToPrim :: (PrimMonad m, PrimState m ~ RealWorld) => IO a -> m a
{-# INLINE ioToPrim #-}
ioToPrim :: forall (m :: * -> *) a.
(PrimMonad m, PrimState m ~ RealWorld) =>
IO a -> m a
ioToPrim = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
stToPrim :: PrimMonad m => ST (PrimState m) a -> m a
{-# INLINE stToPrim #-}
stToPrim :: forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
unsafePrimToPrim :: (PrimBase m1, PrimMonad m2) => m1 a -> m2 a
{-# INLINE unsafePrimToPrim #-}
unsafePrimToPrim :: forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim m1 a
m = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# (forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m1 a
m))
unsafePrimToST :: PrimBase m => m a -> ST s a
{-# INLINE unsafePrimToST #-}
unsafePrimToST :: forall (m :: * -> *) a s. PrimBase m => m a -> ST s a
unsafePrimToST = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
unsafePrimToIO :: PrimBase m => m a -> IO a
{-# INLINE unsafePrimToIO #-}
unsafePrimToIO :: forall (m :: * -> *) a. PrimBase m => m a -> IO a
unsafePrimToIO = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
unsafeSTToPrim :: PrimMonad m => ST s a -> m a
{-# INLINE unsafeSTToPrim #-}
unsafeSTToPrim :: forall (m :: * -> *) s a. PrimMonad m => ST s a -> m a
unsafeSTToPrim = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
unsafeIOToPrim :: PrimMonad m => IO a -> m a
{-# INLINE unsafeIOToPrim #-}
unsafeIOToPrim :: forall (m :: * -> *) a. PrimMonad m => IO a -> m a
unsafeIOToPrim = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
unsafeInlinePrim :: PrimBase m => m a -> a
{-# INLINE unsafeInlinePrim #-}
unsafeInlinePrim :: forall (m :: * -> *) a. PrimBase m => m a -> a
unsafeInlinePrim m a
m = forall a. IO a -> a
unsafeInlineIO (forall (m :: * -> *) a. PrimBase m => m a -> IO a
unsafePrimToIO m a
m)
unsafeInlineIO :: IO a -> a
{-# INLINE unsafeInlineIO #-}
unsafeInlineIO :: forall a. IO a -> a
unsafeInlineIO IO a
m = case forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal IO a
m State# RealWorld
realWorld# of (# State# (PrimState IO)
_, a
r #) -> a
r
unsafeInlineST :: ST s a -> a
{-# INLINE unsafeInlineST #-}
unsafeInlineST :: forall s a. ST s a -> a
unsafeInlineST = forall (m :: * -> *) a. PrimBase m => m a -> a
unsafeInlinePrim
touch :: PrimMonad m => a -> m ()
{-# INLINE touch #-}
touch :: forall (m :: * -> *) a. PrimMonad m => a -> m ()
touch a
x = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
forall a b. (a -> b) -> a -> b
$ (forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (\State# (PrimState IO)
s -> case touch# :: forall a. a -> State# RealWorld -> State# RealWorld
touch# a
x State# (PrimState IO)
s of { State# RealWorld
s' -> (# State# RealWorld
s', () #) }) :: IO ())
touchUnlifted :: forall (m :: Type -> Type) (a :: UnliftedType). PrimMonad m => a -> m ()
{-# INLINE touchUnlifted #-}
touchUnlifted :: forall (m :: * -> *) (a :: UnliftedType). PrimMonad m => a -> m ()
touchUnlifted a
x = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim
forall a b. (a -> b) -> a -> b
$ (forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (\State# (PrimState IO)
s -> case touch# :: forall a. a -> State# RealWorld -> State# RealWorld
touch# a
x State# (PrimState IO)
s of { State# RealWorld
s' -> (# State# RealWorld
s', () #) }) :: IO ())
keepAlive :: PrimBase m
=> a
-> m r
-> m r
#if defined(HAVE_KEEPALIVE)
{-# INLINE keepAlive #-}
keepAlive :: forall (m :: * -> *) a r. PrimBase m => a -> m r -> m r
keepAlive a
x m r
k =
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s0 -> forall s a b.
a
-> State# s -> (State# s -> (# State# s, b #)) -> (# State# s, b #)
keepAliveLiftedLifted# a
x State# (PrimState m)
s0 (forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m r
k)
#else
{-# NOINLINE keepAlive #-}
keepAlive x k = k <* touch x
#endif
keepAliveUnlifted :: forall (m :: Type -> Type) (a :: UnliftedType) (r :: Type). PrimBase m => a -> m r -> m r
#if defined(HAVE_KEEPALIVE)
{-# INLINE keepAliveUnlifted #-}
keepAliveUnlifted :: forall (m :: * -> *) (a :: UnliftedType) r.
PrimBase m =>
a -> m r -> m r
keepAliveUnlifted a
x m r
k =
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s0 -> forall s (a :: UnliftedType) b.
a
-> State# s -> (State# s -> (# State# s, b #)) -> (# State# s, b #)
keepAliveUnliftedLifted# a
x State# (PrimState m)
s0 (forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m r
k)
#else
{-# NOINLINE keepAliveUnlifted #-}
keepAliveUnlifted x k = k <* touchUnlifted x
#endif
evalPrim :: forall a m . PrimMonad m => a -> m a
evalPrim :: forall a (m :: * -> *). PrimMonad m => a -> m a
evalPrim a
a = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (\State# (PrimState m)
s -> forall a d. a -> State# d -> (# State# d, a #)
seq# a
a State# (PrimState m)
s)
noDuplicate :: PrimMonad m => m ()
#if __GLASGOW_HASKELL__ >= 802
noDuplicate :: forall (m :: * -> *). PrimMonad m => m ()
noDuplicate = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \ State# (PrimState m)
s -> (# forall d. State# d -> State# d
noDuplicate# State# (PrimState m)
s, () #)
#else
noDuplicate = unsafeIOToPrim $ primitive $ \s -> (# noDuplicate# s, () #)
#endif
unsafeInterleave, unsafeDupableInterleave :: PrimBase m => m a -> m a
unsafeInterleave :: forall (m :: * -> *) a. PrimBase m => m a -> m a
unsafeInterleave m a
x = forall (m :: * -> *) a. PrimBase m => m a -> m a
unsafeDupableInterleave (forall (m :: * -> *). PrimMonad m => m ()
noDuplicate forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m a
x)
unsafeDupableInterleave :: forall (m :: * -> *) a. PrimBase m => m a -> m a
unsafeDupableInterleave m a
x = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \ State# (PrimState m)
s -> let r' :: a
r' = case forall (m :: * -> *) a.
PrimBase m =>
m a -> State# (PrimState m) -> (# State# (PrimState m), a #)
internal m a
x State# (PrimState m)
s of (# State# (PrimState m)
_, a
r #) -> a
r in (# State# (PrimState m)
s, a
r' #)
{-# INLINE unsafeInterleave #-}
{-# NOINLINE unsafeDupableInterleave #-}