{-# LANGUAGE
BangPatterns,
MagicHash,
RankNTypes,
ScopedTypeVariables,
StandaloneKindSignatures,
TypeOperators,
UnboxedTuples #-}
module Bluefin.Algae.DelCont
( PromptTag
, reset
, shift0
, Continuation
, weakenC1
, resume
, continue
, cancel
) where
import Data.Coerce (coerce)
import Data.Functor (void)
import Data.Kind (Type)
import GHC.Exts (State#, RealWorld, PromptTag#, prompt#, control0#, newPromptTag#)
import GHC.IO (IO(IO))
import Bluefin.Internal (Eff(UnsafeMkEff))
import Bluefin.Eff
import qualified Bluefin.Exception as E
type PromptTag :: Effects -> Type -> Effects -> Type
data PromptTag ss a s = MkPromptTag (PromptTag# a)
reset :: forall a ss.
(forall s. PromptTag ss a s -> Eff (s :& ss) a) ->
Eff ss a
reset :: forall a (ss :: Effects).
(forall (s :: Effects). PromptTag ss a s -> Eff (s :& ss) a)
-> Eff ss a
reset forall (s :: Effects). PromptTag ss a s -> Eff (s :& ss) a
f = IO# a -> Eff ss a
forall a (ss :: Effects). IO# a -> Eff ss a
unsafeMkEff (\State# RealWorld
z0 -> case State# RealWorld -> (# State# RealWorld, PromptTag# a #)
forall a. State# RealWorld -> (# State# RealWorld, PromptTag# a #)
newPromptTag# State# RealWorld
z0 of
(# State# RealWorld
z1, PromptTag# a
tag #) -> PromptTag# a -> IO# a -> IO# a
forall a.
PromptTag# a
-> (State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld
-> (# State# RealWorld, a #)
prompt# PromptTag# a
tag (Eff (Any :& ss) a -> IO# a
forall (ss :: Effects) a. Eff ss a -> IO# a
unsafeRunEff (PromptTag ss a Any -> Eff (Any :& ss) a
forall (s :: Effects). PromptTag ss a s -> Eff (s :& ss) a
f (PromptTag# a -> PromptTag ss a Any
forall (ss :: Effects) a (s :: Effects).
PromptTag# a -> PromptTag ss a s
MkPromptTag PromptTag# a
tag))) State# RealWorld
z1)
newtype Continuation t s b a = MkContinuation (Eff t b -> Eff s a)
weakenC1 :: Continuation t s b a -> Continuation (e :& t) (e :& s) b a
weakenC1 :: forall (t :: Effects) (s :: Effects) b a (e :: Effects).
Continuation t s b a -> Continuation (e :& t) (e :& s) b a
weakenC1 = Continuation t s b a -> Continuation (e :& t) (e :& s) b a
forall a b. Coercible a b => a -> b
coerce
resume :: Continuation t s b a -> Eff t b -> Eff s a
resume :: forall (t :: Effects) (s :: Effects) b a.
Continuation t s b a -> Eff t b -> Eff s a
resume (MkContinuation Eff t b -> Eff s a
k) = Eff t b -> Eff s a
k
continue :: Continuation t s b a -> b -> Eff s a
continue :: forall (t :: Effects) (s :: Effects) b a.
Continuation t s b a -> b -> Eff s a
continue Continuation t s b a
k = Continuation t s b a -> Eff t b -> Eff s a
forall (t :: Effects) (s :: Effects) b a.
Continuation t s b a -> Eff t b -> Eff s a
resume Continuation t s b a
k (Eff t b -> Eff s a) -> (b -> Eff t b) -> b -> Eff s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Eff t b
forall a. a -> Eff t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
cancel :: Continuation t s b a -> Eff s ()
cancel :: forall (t :: Effects) (s :: Effects) b a.
Continuation t s b a -> Eff s ()
cancel Continuation t s b a
k = (forall (ex :: Effects). Exception () ex -> Eff (ex :& s) ())
-> (() -> Eff s ()) -> Eff s ()
forall e (es :: Effects) a.
(forall (ex :: Effects). Exception e ex -> Eff (ex :& es) a)
-> (e -> Eff es a) -> Eff es a
E.catch (\Exception () ex
ex -> Eff (ex :& s) a -> Eff (ex :& s) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Continuation (ex :& t) (ex :& s) b a
-> Eff (ex :& t) b -> Eff (ex :& s) a
forall (t :: Effects) (s :: Effects) b a.
Continuation t s b a -> Eff t b -> Eff s a
resume (Continuation t s b a -> Continuation (ex :& t) (ex :& s) b a
forall (t :: Effects) (s :: Effects) b a (e :: Effects).
Continuation t s b a -> Continuation (e :& t) (e :& s) b a
weakenC1 Continuation t s b a
k) (Exception () ex -> () -> Eff (ex :& t) b
forall (ex :: Effects) (es :: Effects) e a.
(ex :> es) =>
Exception e ex -> e -> Eff es a
E.throw Exception () ex
ex ()))) (\()
_ -> () -> Eff s ()
forall a. a -> Eff s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
shift0 :: forall s a b ss ss0.
s :> ss0 =>
PromptTag ss a s ->
(Continuation ss0 ss b a -> Eff ss a) ->
Eff ss0 b
shift0 :: forall (s :: Effects) a b (ss :: Effects) (ss0 :: Effects).
(s :> ss0) =>
PromptTag ss a s
-> (Continuation ss0 ss b a -> Eff ss a) -> Eff ss0 b
shift0 (MkPromptTag PromptTag# a
tag) Continuation ss0 ss b a -> Eff ss a
f = IO# b -> Eff ss0 b
forall a (ss :: Effects). IO# a -> Eff ss a
unsafeMkEff (\State# RealWorld
z0 ->
PromptTag# a
-> ((IO# b -> State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld -> (# State# RealWorld, a #))
-> IO# b
forall a b.
PromptTag# a
-> (((State# RealWorld -> (# State# RealWorld, b #))
-> State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld
-> (# State# RealWorld, b #)
control0# PromptTag# a
tag (\IO# b -> State# RealWorld -> (# State# RealWorld, a #)
k# ->
Eff ss a -> State# RealWorld -> (# State# RealWorld, a #)
forall (ss :: Effects) a. Eff ss a -> IO# a
unsafeRunEff (Continuation ss0 ss b a -> Eff ss a
f ((IO# b -> State# RealWorld -> (# State# RealWorld, a #))
-> Continuation ss0 ss b a
forall b a (t :: Effects) (s :: Effects).
Continuation# b a -> Continuation t s b a
unsafeContinuation# (PromptTag# a
-> (State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld
-> (# State# RealWorld, a #)
forall a.
PromptTag# a
-> (State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld
-> (# State# RealWorld, a #)
prompt# PromptTag# a
tag ((State# RealWorld -> (# State# RealWorld, a #))
-> State# RealWorld -> (# State# RealWorld, a #))
-> (IO# b -> State# RealWorld -> (# State# RealWorld, a #))
-> IO# b
-> State# RealWorld
-> (# State# RealWorld, a #)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO# b -> State# RealWorld -> (# State# RealWorld, a #)
k#)))) State# RealWorld
z0)
type IO# a = State# RealWorld -> (# State# RealWorld , a #)
type Continuation# a b = IO# a -> IO# b
unsafeMkEff :: IO# a -> Eff ss a
unsafeMkEff :: forall a (ss :: Effects). IO# a -> Eff ss a
unsafeMkEff IO# a
f = IO a -> Eff ss a
forall (es :: Effects) a. IO a -> Eff es a
UnsafeMkEff (IO# a -> IO a
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO IO# a
f)
unsafeRunEff :: Eff ss a -> IO# a
unsafeRunEff :: forall (ss :: Effects) a. Eff ss a -> IO# a
unsafeRunEff (UnsafeMkEff (IO State# RealWorld -> (# State# RealWorld, a #)
f)) = State# RealWorld -> (# State# RealWorld, a #)
f
unsafeContinuation# :: Continuation# b a -> Continuation t s b a
unsafeContinuation# :: forall b a (t :: Effects) (s :: Effects).
Continuation# b a -> Continuation t s b a
unsafeContinuation# Continuation# b a
k = (Eff t b -> Eff s a) -> Continuation t s b a
forall (t :: Effects) (s :: Effects) b a.
(Eff t b -> Eff s a) -> Continuation t s b a
MkContinuation (IO# a -> Eff s a
forall a (ss :: Effects). IO# a -> Eff ss a
unsafeMkEff (IO# a -> Eff s a) -> (Eff t b -> IO# a) -> Eff t b -> Eff s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Continuation# b a
k Continuation# b a -> (Eff t b -> IO# b) -> Eff t b -> IO# a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff t b -> IO# b
forall (ss :: Effects) a. Eff ss a -> IO# a
unsafeRunEff)