{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE DerivingVia #-}
module Bluefin.Internal.Prim where
import Bluefin.Internal
import Bluefin.Internal.OneWayCoercible
import Control.Monad.Primitive qualified as P
import GHC.Exts (State#)
import Unsafe.Coerce (unsafeCoerce)
data Prim (e :: Effects) = UnsafeMkPrim
deriving HandleD Prim
HandleD Prim -> Handle Prim
forall (h :: Effects -> *). HandleD h -> Handle h
$chandleImpl :: HandleD Prim
handleImpl :: HandleD Prim
Handle via OneWayCoercibleHandle Prim
data PrimStateEff (es :: Effects)
instance (e :> es) => OneWayCoercible (Prim e) (Prim es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Prim e) (Prim es)
oneWayCoercibleImpl = OneWayCoercibleD (Prim e) (Prim es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
runPrim ::
(forall e. Prim e -> Eff (e :& es) r) ->
Eff es r
runPrim :: forall (es :: Effects) r.
(forall (e :: Effects). Prim e -> Eff (e :& es) r) -> Eff es r
runPrim forall (e :: Effects). Prim e -> Eff (e :& es) r
k = Eff (es :& es) r -> Eff es r
forall (e :: Effects) r. Eff (e :& e) r -> Eff e r
makeOp (Prim es -> Eff (es :& es) r
forall (e :: Effects). Prim e -> Eff (e :& es) r
k Prim es
forall (e :: Effects). Prim e
UnsafeMkPrim)
primitive ::
(e1 :> es) =>
Prim e1 ->
(State# (PrimStateEff e1) -> (# State# (PrimStateEff e1), a #)) ->
Eff es a
primitive :: forall (e1 :: Effects) (es :: Effects) a.
(e1 :> es) =>
Prim e1
-> (State# (PrimStateEff e1) -> (# State# (PrimStateEff e1), a #))
-> Eff es a
primitive Prim e1
UnsafeMkPrim = ((State# RealWorld -> (# State# RealWorld, Any #)) -> IO Any)
-> (State# (PrimStateEff e1) -> (# State# (PrimStateEff e1), a #))
-> Eff es a
forall a b. a -> b
unsafeCoerce (forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
P.primitive @IO)