HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleprimitive-0.9.1.0Haskell2010

Control.Monad.Primitive

Primitive state-transformer monads.

  • 1 type
  • 4 classes
  • 23 values
  • Packageprimitive-0.9.1.0
  • Exports28
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePrimitive.hs
classclass Monad m => PrimMonad (m :: Type -> Type) where
#

Class of monads which can perform primitive state-transformer actions.

Associated types

Methods

Instances18PrimMonad, …
datadata 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#.

classclass PrimMonad m => PrimBase (m :: Type -> Type) 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.

Methods

Instances4PrimBase
  • PrimBase IODefined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimBase m => PrimBase (IdentityT m)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
valueunsafeInlineIO :: IO a -> a
#

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.

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

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.

valuekeepAlive
  1. :: PrimBase m
  2. => a

    Value x to keep alive while computation k runs.

  3. -> m r

    Computation k

  4. -> 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).