HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Moduleeffectful-core-2.7.1.2GHC2021

Effectful.Internal.Utils

  • 1 type
  • 8 values

Utils for ThreadId

1 declaration

Utils for Any

3 declarations
familytype family Any :: k where
#

The type constructor Any :: forall k. k is a type to which you can unsafely coerce any type, and back.

For unsafeCoerce this means for all lifted types t that unsafeCoerce (unsafeCoerce x :: Any) :: t is equivalent to x and safe.

The same is true for *all* types when using unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep) (a :: TYPE r1) (b :: TYPE r2). a -> b but only if you instantiate r1 and r2 to the same runtime representation. For example using (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE IntRep). a -> b) x is fine, but (unsafeCoerce# :: forall (a :: TYPE IntRep) (b :: TYPE FloatRep). a -> b) will likely cause seg-faults or worse. For this resason, users should always prefer unsafeCoerce over unsafeCoerce# when possible.

Here are some more examples: bad_a1 :: Any (TYPE 'IntRep) bad_a1 = unsafeCoerce# True

bad_a2 :: Any (TYPE ('BoxedRep 'UnliftedRep)) bad_a2 = unsafeCoerce# True Here bad_a1 is bad because we started with True :: (Bool :: Type), represented by a boxed heap pointer, and coerced it to a1 :: Any (TYPE 'IntRep), whose representation is a non-pointer integer. That's why we had to use unsafeCoerce#; it is really unsafe because it can change representations. Similarly bad_a2 is bad because although both True and bad_a2 are represented by a heap pointer, True is lifted but bad_a2@ is not; bugs here may be rather subtle.

If you must use unsafeCoerce# to cast to Any, type annotations are recommended to make sure that Any has the correct kind. As casting between different runtimereps is unsound. For example to cast a ByteArray# to Any you might use: unsafeCoerce# b :: (Any :: TYPE ('BoxedRep 'Unlifted))

Unique

2 declarations
newtypenewtype Unique
#

A unique with no possibility for CAS contention.

Credits for this go to Edward Kmett.

Instances1Eq
  • Eq UniqueDefined in effectful-core-2.7.1.2 · Effectful.Internal.Utils

CallStack

1 declaration

Remove exactly one layer of freezing, i.e. the one added by send and friends via withFrozenCallStack. Freezes applied by client code need to stay intact, so this must not recurse.

Array capacity

1 declaration

Utils for MutablePrimArray

1 declaration