HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleprimitive-unlifted-2.1.0.0Haskell2010

Data.Primitive.Unlifted.Weak.IO

A version of Data.Primitive.Unlifted.Weak specialized to the IO type.

  • 2 types
  • 10 values
datadata UnliftedWeak_ (a :: k) (unlifted_a :: UnliftedType)
#

A weak pointer from a key (which may be lifted or unlifted) to an unlifted value. In UnliftedWeak_ a unlifted_a, it is generally expected that unlifted_a ~ Unlifted a, but enforcing that here would lead to unfortunate type roles. See System.Mem.Weak for detailed information about weak references, including the notes at the end of that module.

Constructors

Instances2PrimUnlifted, Unlifted
typetype UnliftedWeak a = UnliftedWeak_ a (Unlifted a)
#

A type synonym for an UnliftedWeak_ containing lifted values of a particular type. As a general rule, this type synonym should not be used in class instances—use UnliftedWeak_ with an equality constraint instead. It also should not be used when defining newtypes or datatypes, unless those will have restrictive type roles regardless—use UnliftedWeak_ instead.

valuemkUnliftedWeakPtr
  1. :: PrimUnlifted k
  2. => k
  3. -> Maybe (IO ())
  4. -> IO (UnliftedWeak k)
#

Make a weak pointer from an unlifted value to itself.

Note: This should generally be preferred to Data.IORef.mkWeakIORef and similar for making weak pointers to IORefs, MVars, TVars, etc, as the values are stored more directly and compactly this way.

valueaddFinalizerUnlifted :: PrimUnlifted k => k -> IO () -> IO ()
#

A specialised version of mkUnliftedWeakPtr, where the UnliftedWeak object returned is simply thrown away (however the finalizer will be remembered by the garbage collector, and will still be run when the key becomes unreachable).

valuetouchUnlifted :: PrimUnlifted a => a -> IO ()
#

Ensure that a value is considered live by the garbage collector at a particular point in the program. Typically, this is used to prevent foreign resources from being finalized while they are still being used.

Considerable care is required when using this operation (see GHC ticket 14346). In particular, if GHC sees that an action m will never complete normally, then it will simplify m >> touchUnlifted a to m, allowing a to die prematurely. For now, functions using touchUnlifted may require careful use of NOINLINE to work around this; in the future, GHC will probably provide a more robust operation for keeping values alive.