{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnliftedNewtypes #-}
{-# OPTIONS_HADDOCK not-home #-}
module Bluefin.Internal where
import Bluefin.Internal.Exception.Scoped qualified as ScopedException
import Bluefin.Internal.OneWayCoercible
( OneWayCoercible (oneWayCoercibleImpl),
OneWayCoercibleD,
OneWayCoercion,
gOneWayCoercible,
oneWayCoercible,
oneWayCoercion,
trans3D,
unsafeCoercionOfOneWayCoercion,
unsafeOneWayCoerce,
unsafeOneWayCoercible,
)
import Bluefin.Internal.Vault (Vault)
import Bluefin.Internal.Vault qualified as Vault
import Control.Concurrent (forkIO, forkIOWithUnmask, killThread, myThreadId, throwTo)
import Control.Concurrent.Async qualified as Async
import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar, takeMVar)
import Control.Exception qualified
import Control.Monad (forever)
import Control.Monad.Base (MonadBase (liftBase))
import Control.Monad.Fix (MonadFix)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.IO.Unlift (MonadUnliftIO, withRunInIO)
import Control.Monad.Trans.Control (MonadBaseControl, StM, liftBaseWith, restoreM)
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Trans.Reader qualified as Reader
import Data.Coerce (Coercible, coerce)
import Data.Foldable (for_)
import Data.Function (fix)
import Data.IORef (IORef, modifyIORef', newIORef, readIORef, writeIORef)
import Data.Kind (Type)
import Data.Proxy (Proxy (Proxy))
import Data.Type.Coercion (Coercion (Coercion))
import GHC.Exts (Any, Proxy#, keepAlive#, proxy#)
import GHC.Generics (Generic, M1, Rec1, (:*:))
import GHC.IO (IO (..))
import System.IO.Unsafe (unsafePerformIO)
import System.Mem.Weak (addFinalizer)
import Unsafe.Coerce (unsafeCoerce)
import Prelude hiding (drop, head, read, return)
data Effects = Union Effects Effects
infixr 9 :&
type (:&) = Union
type Env = IORef Vault
newtype Eff (es :: Effects) a = UnsafeMkEff {forall (es :: Effects) a. Eff es a -> Env -> IO a
unsafeUnEff :: Env -> IO a}
deriving stock ((forall a b. (a -> b) -> Eff es a -> Eff es b)
-> (forall a b. a -> Eff es b -> Eff es a) -> Functor (Eff es)
forall a b. a -> Eff es b -> Eff es a
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (es :: Effects) a b. a -> Eff es b -> Eff es a
forall (es :: Effects) a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (es :: Effects) a b. (a -> b) -> Eff es a -> Eff es b
fmap :: forall a b. (a -> b) -> Eff es a -> Eff es b
$c<$ :: forall (es :: Effects) a b. a -> Eff es b -> Eff es a
<$ :: forall a b. a -> Eff es b -> Eff es a
Functor)
deriving (Functor (Eff es)
Functor (Eff es) =>
(forall a. a -> Eff es a)
-> (forall a b. Eff es (a -> b) -> Eff es a -> Eff es b)
-> (forall a b c.
(a -> b -> c) -> Eff es a -> Eff es b -> Eff es c)
-> (forall a b. Eff es a -> Eff es b -> Eff es b)
-> (forall a b. Eff es a -> Eff es b -> Eff es a)
-> Applicative (Eff es)
forall a. a -> Eff es a
forall a b. Eff es a -> Eff es b -> Eff es a
forall a b. Eff es a -> Eff es b -> Eff es b
forall a b. Eff es (a -> b) -> Eff es a -> Eff es b
forall a b c. (a -> b -> c) -> Eff es a -> Eff es b -> Eff es c
forall (es :: Effects). Functor (Eff es)
forall (es :: Effects) a. a -> Eff es a
forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es a
forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es b
forall (es :: Effects) a b. Eff es (a -> b) -> Eff es a -> Eff es b
forall (es :: Effects) a b c.
(a -> b -> c) -> Eff es a -> Eff es b -> Eff es c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall (es :: Effects) a. a -> Eff es a
pure :: forall a. a -> Eff es a
$c<*> :: forall (es :: Effects) a b. Eff es (a -> b) -> Eff es a -> Eff es b
<*> :: forall a b. Eff es (a -> b) -> Eff es a -> Eff es b
$cliftA2 :: forall (es :: Effects) a b c.
(a -> b -> c) -> Eff es a -> Eff es b -> Eff es c
liftA2 :: forall a b c. (a -> b -> c) -> Eff es a -> Eff es b -> Eff es c
$c*> :: forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es b
*> :: forall a b. Eff es a -> Eff es b -> Eff es b
$c<* :: forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es a
<* :: forall a b. Eff es a -> Eff es b -> Eff es a
Applicative, Applicative (Eff es)
Applicative (Eff es) =>
(forall a b. Eff es a -> (a -> Eff es b) -> Eff es b)
-> (forall a b. Eff es a -> Eff es b -> Eff es b)
-> (forall a. a -> Eff es a)
-> Monad (Eff es)
forall a. a -> Eff es a
forall a b. Eff es a -> Eff es b -> Eff es b
forall a b. Eff es a -> (a -> Eff es b) -> Eff es b
forall (es :: Effects). Applicative (Eff es)
forall (es :: Effects) a. a -> Eff es a
forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es b
forall (es :: Effects) a b. Eff es a -> (a -> Eff es b) -> Eff es b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (es :: Effects) a b. Eff es a -> (a -> Eff es b) -> Eff es b
>>= :: forall a b. Eff es a -> (a -> Eff es b) -> Eff es b
$c>> :: forall (es :: Effects) a b. Eff es a -> Eff es b -> Eff es b
>> :: forall a b. Eff es a -> Eff es b -> Eff es b
$creturn :: forall (es :: Effects) a. a -> Eff es a
return :: forall a. a -> Eff es a
Monad, Monad (Eff es)
Monad (Eff es) =>
(forall a. (a -> Eff es a) -> Eff es a) -> MonadFix (Eff es)
forall a. (a -> Eff es a) -> Eff es a
forall (es :: Effects). Monad (Eff es)
forall (es :: Effects) a. (a -> Eff es a) -> Eff es a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
$cmfix :: forall (es :: Effects) a. (a -> Eff es a) -> Eff es a
mfix :: forall a. (a -> Eff es a) -> Eff es a
MonadFix) via ReaderT Env IO
type role Eff nominal representational
instance (e <: es) => OneWayCoercible (Eff e) (Eff es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Eff e) (Eff es)
oneWayCoercibleImpl = OneWayCoercibleD (Eff e) (Eff es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
instance (e <: es) => OneWayCoercible (Eff e r) (Eff es r) where
oneWayCoercibleImpl :: OneWayCoercibleD (Eff e r) (Eff es r)
oneWayCoercibleImpl = OneWayCoercibleD (Eff e r) (Eff es r)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
newtype EffReader r es a = MkEffReader {forall r (es :: Effects) a. EffReader r es a -> r -> Eff es a
unEffReader :: r -> Eff es a}
deriving ((forall a b. (a -> b) -> EffReader r es a -> EffReader r es b)
-> (forall a b. a -> EffReader r es b -> EffReader r es a)
-> Functor (EffReader r es)
forall a b. a -> EffReader r es b -> EffReader r es a
forall a b. (a -> b) -> EffReader r es a -> EffReader r es b
forall r (es :: Effects) a b.
a -> EffReader r es b -> EffReader r es a
forall r (es :: Effects) a b.
(a -> b) -> EffReader r es a -> EffReader r es b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall r (es :: Effects) a b.
(a -> b) -> EffReader r es a -> EffReader r es b
fmap :: forall a b. (a -> b) -> EffReader r es a -> EffReader r es b
$c<$ :: forall r (es :: Effects) a b.
a -> EffReader r es b -> EffReader r es a
<$ :: forall a b. a -> EffReader r es b -> EffReader r es a
Functor, Functor (EffReader r es)
Functor (EffReader r es) =>
(forall a. a -> EffReader r es a)
-> (forall a b.
EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b)
-> (forall a b c.
(a -> b -> c)
-> EffReader r es a -> EffReader r es b -> EffReader r es c)
-> (forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b)
-> (forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es a)
-> Applicative (EffReader r es)
forall a. a -> EffReader r es a
forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es a
forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
forall a b.
EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b
forall a b c.
(a -> b -> c)
-> EffReader r es a -> EffReader r es b -> EffReader r es c
forall r (es :: Effects). Functor (EffReader r es)
forall r (es :: Effects) a. a -> EffReader r es a
forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es a
forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
forall r (es :: Effects) a b.
EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b
forall r (es :: Effects) a b c.
(a -> b -> c)
-> EffReader r es a -> EffReader r es b -> EffReader r es c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall r (es :: Effects) a. a -> EffReader r es a
pure :: forall a. a -> EffReader r es a
$c<*> :: forall r (es :: Effects) a b.
EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b
<*> :: forall a b.
EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b
$cliftA2 :: forall r (es :: Effects) a b c.
(a -> b -> c)
-> EffReader r es a -> EffReader r es b -> EffReader r es c
liftA2 :: forall a b c.
(a -> b -> c)
-> EffReader r es a -> EffReader r es b -> EffReader r es c
$c*> :: forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
*> :: forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
$c<* :: forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es a
<* :: forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es a
Applicative, Applicative (EffReader r es)
Applicative (EffReader r es) =>
(forall a b.
EffReader r es a -> (a -> EffReader r es b) -> EffReader r es b)
-> (forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b)
-> (forall a. a -> EffReader r es a)
-> Monad (EffReader r es)
forall a. a -> EffReader r es a
forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
forall a b.
EffReader r es a -> (a -> EffReader r es b) -> EffReader r es b
forall r (es :: Effects). Applicative (EffReader r es)
forall r (es :: Effects) a. a -> EffReader r es a
forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
forall r (es :: Effects) a b.
EffReader r es a -> (a -> EffReader r es b) -> EffReader r es b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall r (es :: Effects) a b.
EffReader r es a -> (a -> EffReader r es b) -> EffReader r es b
>>= :: forall a b.
EffReader r es a -> (a -> EffReader r es b) -> EffReader r es b
$c>> :: forall r (es :: Effects) a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
>> :: forall a b.
EffReader r es a -> EffReader r es b -> EffReader r es b
$creturn :: forall r (es :: Effects) a. a -> EffReader r es a
return :: forall a. a -> EffReader r es a
Monad) via (Reader.ReaderT r (Eff es))
instance (e <: es) => MonadIO (EffReader (IOE e) es) where
liftIO :: forall a. IO a -> EffReader (IOE e) es a
liftIO = (IOE e -> Eff es a) -> EffReader (IOE e) es a
forall r (es :: Effects) a. (r -> Eff es a) -> EffReader r es a
MkEffReader ((IOE e -> Eff es a) -> EffReader (IOE e) es a)
-> (IO a -> IOE e -> Eff es a) -> IO a -> EffReader (IOE e) es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IOE e -> IO a -> Eff es a) -> IO a -> IOE e -> Eff es a
forall a b c. (a -> b -> c) -> b -> a -> c
flip IOE e -> IO a -> Eff es a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO
effReader :: (r -> Eff es a) -> EffReader r es a
effReader :: forall r (es :: Effects) a. (r -> Eff es a) -> EffReader r es a
effReader = (r -> Eff es a) -> EffReader r es a
forall r (es :: Effects) a. (r -> Eff es a) -> EffReader r es a
MkEffReader
runEffReader :: r -> EffReader r es a -> Eff es a
runEffReader :: forall r (es :: Effects) a. r -> EffReader r es a -> Eff es a
runEffReader r
r (MkEffReader r -> Eff es a
m) = r -> Eff es a
m r
r
withEffToIO ::
(e2 <: es) =>
((forall r. (forall e1. IOE e1 -> Eff (e1 :& es) r) -> IO r) -> IO a) ->
IOE e2 ->
Eff es a
withEffToIO :: forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> IOE e2 -> Eff es a
withEffToIO (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k IOE e2
io = (Env -> IO a) -> Eff es a
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff (\Env
env -> (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k (\forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r
f -> Eff (e2 :& es) r -> Env -> IO r
forall (es :: Effects) a. Eff es a -> Env -> IO a
unsafeUnEff (IOE e2 -> Eff (e2 :& es) r
forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r
f IOE e2
io) Env
env))
withEffToIO' ::
(e2 <: es) =>
IOE e2 ->
((forall r. (forall e1. IOE e1 -> Eff (e1 :& es) r) -> IO r) -> IO a) ->
Eff es a
withEffToIO' :: forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
IOE e2
-> ((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> Eff es a
withEffToIO' IOE e2
io (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k = ((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> IOE e2 -> Eff es a
forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> IOE e2 -> Eff es a
withEffToIO (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k IOE e2
io
withEffToIO_ ::
(e <: es) =>
IOE e ->
((forall r. Eff es r -> IO r) -> IO a) ->
Eff es a
withEffToIO_ :: forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e
io (forall r. Eff es r -> IO r) -> IO a
k =
((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> IOE e -> Eff es a
forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> IOE e2 -> Eff es a
withEffToIO (\forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r
effToIO -> (forall r. Eff es r -> IO r) -> IO a
k (\Eff es r
eff -> (forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r
forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r
effToIO (\IOE e1
_ -> Eff es r -> Eff (e1 :& es) r
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl Eff es r
eff))) IOE e
io
withEffToIO_' ::
(e2 <: es) =>
IOE e2 ->
((forall r. (forall e1. IOE e1 -> Eff (e1 :& es) r) -> IO r) -> IO a) ->
Eff es a
withEffToIO_' :: forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
IOE e2
-> ((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> Eff es a
withEffToIO_' IOE e2
io (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k =
IOE e2 -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e2
io (\forall r. Eff es r -> IO r
effToIO -> (forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a
k (\forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r
eff -> Eff es r -> IO r
forall r. Eff es r -> IO r
effToIO (In (e2 :& es) es -> Eff (e2 :& es) r -> Eff es r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (In e2 es -> In (e2 :& es) es
forall (e1 :: Effects) (e2 :: Effects).
In e1 e2 -> In (e1 :& e2) e2
subsume2 In e2 es
forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has) (IOE e2 -> Eff (e2 :& es) r
forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r
eff IOE e2
io))))
instance (e <: es) => MonadUnliftIO (EffReader (IOE e) es) where
withRunInIO ::
((forall a. EffReader (IOE e) es a -> IO a) -> IO b) ->
EffReader (IOE e) es b
withRunInIO :: forall b.
((forall a. EffReader (IOE e) es a -> IO a) -> IO b)
-> EffReader (IOE e) es b
withRunInIO (forall a. EffReader (IOE e) es a -> IO a) -> IO b
k =
(IOE e -> Eff es b) -> EffReader (IOE e) es b
forall r (es :: Effects) a. (r -> Eff es a) -> EffReader r es a
MkEffReader ((IOE e -> Eff es b) -> EffReader (IOE e) es b)
-> (IOE e -> Eff es b) -> EffReader (IOE e) es b
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
IOE e -> ((forall {r}. Eff es r -> IO r) -> IO b) -> Eff es b
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e
io (((forall {r}. Eff es r -> IO r) -> IO b) -> Eff es b)
-> ((forall {r}. Eff es r -> IO r) -> IO b) -> Eff es b
forall a b. (a -> b) -> a -> b
$ \forall {r}. Eff es r -> IO r
effToIO -> do
(forall a. EffReader (IOE e) es a -> IO a) -> IO b
k ((forall a. EffReader (IOE e) es a -> IO a) -> IO b)
-> (forall a. EffReader (IOE e) es a -> IO a) -> IO b
forall a b. (a -> b) -> a -> b
$ \(MkEffReader IOE e -> Eff es a
f) -> do
Eff es a -> IO a
forall {r}. Eff es r -> IO r
effToIO (IOE e -> Eff es a
f IOE e
io)
race ::
(e2 <: es) =>
(forall e. IOE e -> Eff (e :& es) a) ->
(forall e. IOE e -> Eff (e :& es) a) ->
IOE e2 ->
Eff es a
race :: forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
(forall (e :: Effects). IOE e -> Eff (e :& es) a)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) a)
-> IOE e2
-> Eff es a
race forall (e :: Effects). IOE e -> Eff (e :& es) a
x forall (e :: Effects). IOE e -> Eff (e :& es) a
y IOE e2
io = do
Either a a
r <- IOE e2
-> ((forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO (Either a a))
-> Eff es (Either a a)
forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
IOE e2
-> ((forall r.
(forall (e1 :: Effects). IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO a)
-> Eff es a
withEffToIO' IOE e2
io (((forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO (Either a a))
-> Eff es (Either a a))
-> ((forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r)
-> IO (Either a a))
-> Eff es (Either a a)
forall a b. (a -> b) -> a -> b
$ \forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r
toIO ->
IO a -> IO a -> IO (Either a a)
forall a b. IO a -> IO b -> IO (Either a b)
Async.race ((forall (e :: Effects). IOE e -> Eff (e :& es) a) -> IO a
forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r
toIO (Eff (e1 :& es) a -> Eff (e1 :& es) a
forall (es :: Effects) r. Eff es r -> Eff es r
withClonedEnv (Eff (e1 :& es) a -> Eff (e1 :& es) a)
-> (IOE e1 -> Eff (e1 :& es) a) -> IOE e1 -> Eff (e1 :& es) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOE e1 -> Eff (e1 :& es) a
forall (e :: Effects). IOE e -> Eff (e :& es) a
x)) ((forall (e :: Effects). IOE e -> Eff (e :& es) a) -> IO a
forall {r}.
(forall {e1 :: Effects}. IOE e1 -> Eff (e1 :& es) r) -> IO r
toIO (Eff (e1 :& es) a -> Eff (e1 :& es) a
forall (es :: Effects) r. Eff es r -> Eff es r
withClonedEnv (Eff (e1 :& es) a -> Eff (e1 :& es) a)
-> (IOE e1 -> Eff (e1 :& es) a) -> IOE e1 -> Eff (e1 :& es) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOE e1 -> Eff (e1 :& es) a
forall (e :: Effects). IOE e -> Eff (e :& es) a
y))
a -> Eff es a
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Eff es a) -> a -> Eff es a
forall a b. (a -> b) -> a -> b
$ case Either a a
r of
Left a
a -> a
a
Right a
a -> a
a
withClonedEnv :: Eff es r -> Eff es r
withClonedEnv :: forall (es :: Effects) r. Eff es r -> Eff es r
withClonedEnv Eff es r
m = (Env -> IO r) -> Eff es r
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO r) -> Eff es r) -> (Env -> IO r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \Env
vault -> do
Env
vault' <- Env -> IO Env
forall {a}. IORef a -> IO (IORef a)
cloneIORef Env
vault
case Eff es r
m of UnsafeMkEff Env -> IO r
m' -> Env -> IO r
m' Env
vault'
where
cloneIORef :: IORef a -> IO (IORef a)
cloneIORef IORef a
ref = do
a
orig <- IORef a -> IO a
forall a. IORef a -> IO a
readIORef IORef a
ref
a -> IO (IORef a)
forall a. a -> IO (IORef a)
newIORef a
orig
connectCoroutines ::
forall es a b r.
(forall e. Coroutine a b e -> Eff (e :& es) r) ->
(forall e. a -> Coroutine b a e -> Eff (e :& es) r) ->
Eff es r
connectCoroutines :: forall (es :: Effects) a b r.
(forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r)
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r)
-> Eff es r
connectCoroutines forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r
m1 forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r
m2 = (forall (e :: Effects). IOE e -> Eff (e :& es) r) -> Eff es r
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) r) -> Eff es r)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
MVar a
av <- IOE e -> IO (MVar a) -> Eff (e :& es) (MVar a)
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io IO (MVar a)
forall a. IO (MVar a)
newEmptyMVar
MVar b
bv <- IOE e -> IO (MVar b) -> Eff (e :& es) (MVar b)
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io IO (MVar b)
forall a. IO (MVar a)
newEmptyMVar
let t1 :: forall e. IOE e -> Eff (e :& es) r
t1 :: forall (e :: Effects). IOE e -> Eff (e :& es) r
t1 IOE e
io' = (forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& (e :& es)) r)
-> (a -> Eff (e :& es) b) -> Eff (e :& es) r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r)
-> (Request a b e1 -> Eff (e1 :& es) r)
-> Request a b e1
-> Eff (e1 :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request a b e1 -> Eff (e1 :& es) r
forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r
m1) ((a -> Eff (e :& es) b) -> Eff (e :& es) r)
-> (a -> Eff (e :& es) b) -> Eff (e :& es) r
forall a b. (a -> b) -> a -> b
$ \a
a -> IOE e -> IO b -> Eff (e :& es) b
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io' (IO b -> Eff (e :& es) b) -> IO b -> Eff (e :& es) b
forall a b. (a -> b) -> a -> b
$ do
MVar a -> a -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar a
av a
a
MVar b -> IO b
forall a. MVar a -> IO a
takeMVar MVar b
bv
let t2 :: forall e. IOE e -> Eff (e :& es) r
t2 :: forall (e :: Effects). IOE e -> Eff (e :& es) r
t2 IOE e
io' = do
a
ainit <- IOE e -> IO a -> Eff (e :& es) a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io' (MVar a -> IO a
forall a. MVar a -> IO a
takeMVar MVar a
av)
(forall (e1 :: Effects). Request b a e1 -> Eff (e1 :& (e :& es)) r)
-> (b -> Eff (e :& es) a) -> Eff (e :& es) r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r)
-> (Request b a e1 -> Eff (e1 :& es) r)
-> Request b a e1
-> Eff (e1 :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Request b a e1 -> Eff (e1 :& es) r
forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r
m2 a
ainit) ((b -> Eff (e :& es) a) -> Eff (e :& es) r)
-> (b -> Eff (e :& es) a) -> Eff (e :& es) r
forall a b. (a -> b) -> a -> b
$ \b
b_ -> IOE e -> IO a -> Eff (e :& es) a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io' (IO a -> Eff (e :& es) a) -> IO a -> Eff (e :& es) a
forall a b. (a -> b) -> a -> b
$ do
MVar b -> b -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar b
bv b
b_
MVar a -> IO a
forall a. MVar a -> IO a
takeMVar MVar a
av
(forall (e :: Effects). IOE e -> Eff (e :& (e :& es)) r)
-> (forall (e :: Effects). IOE e -> Eff (e :& (e :& es)) r)
-> IOE e
-> Eff (e :& es) r
forall (e2 :: Effects) (es :: Effects) a.
(e2 <: es) =>
(forall (e :: Effects). IOE e -> Eff (e :& es) a)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) a)
-> IOE e2
-> Eff es a
race (Eff (e :& es) r -> Eff (e :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e :& es) r -> Eff (e :& (e :& es)) r)
-> (IOE e -> Eff (e :& es) r) -> IOE e -> Eff (e :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOE e -> Eff (e :& es) r
forall (e :: Effects). IOE e -> Eff (e :& es) r
t1) (Eff (e :& es) r -> Eff (e :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e :& es) r -> Eff (e :& (e :& es)) r)
-> (IOE e -> Eff (e :& es) r) -> IOE e -> Eff (e :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOE e -> Eff (e :& es) r
forall (e :: Effects). IOE e -> Eff (e :& es) r
t2) IOE e
io
receiveStream ::
(forall e. Consume a e -> Eff (e :& es) r) ->
(forall e. Stream a e -> Eff (e :& es) r) ->
Eff es r
receiveStream :: forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
receiveStream = (forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
consumeStream
consumeStream ::
(forall e. Consume a e -> Eff (e :& es) r) ->
(forall e. Stream a e -> Eff (e :& es) r) ->
Eff es r
consumeStream :: forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
consumeStream forall (e :: Effects). Consume a e -> Eff (e :& es) r
r forall (e :: Effects). Stream a e -> Eff (e :& es) r
s = (forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects).
() -> Coroutine a () e -> Eff (e :& es) r)
-> Eff es r
forall (es :: Effects) a b r.
(forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r)
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r)
-> Eff es r
connectCoroutines Consume a e -> Eff (e :& es) r
forall (e :: Effects). Consume a e -> Eff (e :& es) r
r (\() -> Coroutine a () e -> Eff (e :& es) r
forall (e :: Effects). Stream a e -> Eff (e :& es) r
s)
streamConsume ::
forall a (es :: Effects) r.
(forall (e :: Effects). Stream a e -> Eff (e :& es) r) ->
(forall (e :: Effects). Consume a e -> Eff (e :& es) r) ->
Eff es r
streamConsume :: forall a (es :: Effects) r.
(forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> Eff es r
streamConsume forall (e :: Effects). Stream a e -> Eff (e :& es) r
s forall (e :: Effects). Consume a e -> Eff (e :& es) r
c = (forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
consumeStream Consume a e -> Eff (e :& es) r
forall (e :: Effects). Consume a e -> Eff (e :& es) r
c Stream a e -> Eff (e :& es) r
forall (e :: Effects). Stream a e -> Eff (e :& es) r
s
instance (e <: es) => MonadBase IO (EffReader (IOE e) es) where
liftBase :: forall α. IO α -> EffReader (IOE e) es α
liftBase = IO α -> EffReader (IOE e) es α
forall α. IO α -> EffReader (IOE e) es α
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
instance (e <: es) => MonadBaseControl IO (EffReader (IOE e) es) where
type StM (EffReader (IOE e) es) a = a
liftBaseWith :: forall a.
(RunInBase (EffReader (IOE e) es) IO -> IO a)
-> EffReader (IOE e) es a
liftBaseWith = ((forall a. EffReader (IOE e) es a -> IO a) -> IO a)
-> EffReader (IOE e) es a
(RunInBase (EffReader (IOE e) es) IO -> IO a)
-> EffReader (IOE e) es a
forall b.
((forall a. EffReader (IOE e) es a -> IO a) -> IO b)
-> EffReader (IOE e) es b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO
restoreM :: forall a. StM (EffReader (IOE e) es) a -> EffReader (IOE e) es a
restoreM = a -> EffReader (IOE e) es a
StM (EffReader (IOE e) es) a -> EffReader (IOE e) es a
forall a. a -> EffReader (IOE e) es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance (e <: es) => MonadFail (EffReader (Throw String e) es) where
fail :: forall a. String -> EffReader (Throw String e) es a
fail = (Throw String e -> Eff es a) -> EffReader (Throw String e) es a
forall r (es :: Effects) a. (r -> Eff es a) -> EffReader r es a
MkEffReader ((Throw String e -> Eff es a) -> EffReader (Throw String e) es a)
-> (String -> Throw String e -> Eff es a)
-> String
-> EffReader (Throw String e) es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Throw String e -> String -> Eff es a)
-> String -> Throw String e -> Eff es a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Throw String e -> String -> Eff es a
forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
throw
hoistReader ::
(forall b. m b -> n b) ->
Reader.ReaderT r m a ->
Reader.ReaderT r n a
hoistReader :: forall (m :: * -> *) (n :: * -> *) r a.
(forall b. m b -> n b) -> ReaderT r m a -> ReaderT r n a
hoistReader forall b. m b -> n b
f = (r -> n a) -> ReaderT r n a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
Reader.ReaderT ((r -> n a) -> ReaderT r n a)
-> (ReaderT r m a -> r -> n a) -> ReaderT r m a -> ReaderT r n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\ReaderT r m a
m -> m a -> n a
forall b. m b -> n b
f (m a -> n a) -> (r -> m a) -> r -> n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
Reader.runReaderT ReaderT r m a
m)
withMonadIO ::
(e <: es) =>
IOE e ->
(forall m. (MonadIO m) => m r) ->
Eff es r
withMonadIO :: forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
IOE e -> (forall (m :: * -> *). MonadIO m => m r) -> Eff es r
withMonadIO IOE e
io forall (m :: * -> *). MonadIO m => m r
m = EffReader (IOE e) es r -> IOE e -> Eff es r
forall r (es :: Effects) a. EffReader r es a -> r -> Eff es a
unEffReader EffReader (IOE e) es r
forall (m :: * -> *). MonadIO m => m r
m IOE e
io
withMonadFail ::
(e <: es) =>
Throw String e ->
(forall m. (MonadFail m) => m r) ->
Eff es r
withMonadFail :: forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Throw String e
-> (forall (m :: * -> *). MonadFail m => m r) -> Eff es r
withMonadFail Throw String e
f forall (m :: * -> *). MonadFail m => m r
m = EffReader (Throw String e) es r -> Throw String e -> Eff es r
forall r (es :: Effects) a. EffReader r es a -> r -> Eff es a
unEffReader EffReader (Throw String e) es r
forall (m :: * -> *). MonadFail m => m r
m Throw String e
f
runPureEff :: (forall es. Eff es a) -> a
runPureEff :: forall a. (forall (es :: Effects). Eff es a) -> a
runPureEff = (forall (es :: Effects). Eff es a) -> a
forall a. (forall (es :: Effects). Eff es a) -> a
runPureEffPoisonable
runPureEffPoisonable :: (forall es. Eff es a) -> a
runPureEffPoisonable :: forall a. (forall (es :: Effects). Eff es a) -> a
runPureEffPoisonable forall (es :: Effects). Eff es a
e = IO a -> a
forall a. IO a -> a
unsafePerformIO ((forall (e :: Effects). IOE e -> Eff e a) -> IO a
forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff (\IOE e
_ -> Eff e a
forall (es :: Effects). Eff es a
e))
runPureEffAsyncSafe :: (forall es. Eff es a) -> a
runPureEffAsyncSafe :: forall a. (forall (es :: Effects). Eff es a) -> a
runPureEffAsyncSafe forall (es :: Effects). Eff es a
e = IO a -> a
forall a. IO a -> a
unsafePerformIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ do
MVar (Either SomeException a)
result <- IO (MVar (Either SomeException a))
forall a. IO (MVar a)
newEmptyMVar
IORef ()
owner <- () -> IO (IORef ())
forall a. a -> IO (IORef a)
newIORef ()
ThreadId
_ <- IO ThreadId -> IO ThreadId
forall a. IO a -> IO a
Control.Exception.mask_ (IO ThreadId -> IO ThreadId) -> IO ThreadId -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forkIOWithUnmask (((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId)
-> ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
unmask -> do
ThreadId
tid <- IO ThreadId
myThreadId
IORef () -> IO () -> IO ()
forall key. key -> IO () -> IO ()
addFinalizer IORef ()
owner (ThreadId -> IO ()
killThread ThreadId
tid)
Either SomeException a
r <- forall e a. Exception e => IO a -> IO (Either e a)
Control.Exception.try @Control.Exception.SomeException (IO a -> IO (Either SomeException a))
-> (IO a -> IO a) -> IO a -> IO (Either SomeException a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> IO a
forall a. IO a -> IO a
unmask (IO a -> IO (Either SomeException a))
-> IO a -> IO (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ do
(forall (e :: Effects). IOE e -> Eff e a) -> IO a
forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff (\IOE e
_ -> Eff e a
forall (es :: Effects). Eff es a
e)
MVar (Either SomeException a) -> Either SomeException a -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either SomeException a)
result Either SomeException a
r
Either SomeException a
r <- IORef ()
-> IO (Either SomeException a) -> IO (Either SomeException a)
forall a b. a -> IO b -> IO b
keepAlive IORef ()
owner (MVar (Either SomeException a) -> IO (Either SomeException a)
forall a. MVar a -> IO a
readMVar MVar (Either SomeException a)
result)
(SomeException -> IO a)
-> (a -> IO a) -> Either SomeException a -> IO a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> IO a
forall e a. Exception e => e -> IO a
Control.Exception.throwIO a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Either SomeException a
r
keepAlive :: a -> IO b -> IO b
keepAlive :: forall a b. a -> IO b -> IO b
keepAlive a
a (IO State# RealWorld -> (# State# RealWorld, b #)
action) = (State# RealWorld -> (# State# RealWorld, b #)) -> IO b
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, b #)) -> IO b)
-> (State# RealWorld -> (# State# RealWorld, b #)) -> IO b
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> a
-> State# RealWorld
-> (State# RealWorld -> (# State# RealWorld, b #))
-> (# State# RealWorld, b #)
forall a d b. a -> State# d -> (State# d -> b) -> b
keepAlive# a
a State# RealWorld
s State# RealWorld -> (# State# RealWorld, b #)
action
runPureEffAsyncSafeRestarting :: (forall es. Eff es a) -> a
runPureEffAsyncSafeRestarting :: forall a. (forall (es :: Effects). Eff es a) -> a
runPureEffAsyncSafeRestarting forall (es :: Effects). Eff es a
effBody = IO a -> a
forall a. IO a -> a
unsafePerformIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$
((forall a. IO a -> IO a) -> IO a) -> IO a
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
Control.Exception.mask (((forall a. IO a -> IO a) -> IO a) -> IO a)
-> ((forall a. IO a -> IO a) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
MVar ThreadId
tidVar <- IO (MVar ThreadId)
forall a. IO (MVar a)
newEmptyMVar
MVar (Either SomeException a)
done <- IO (MVar (Either SomeException a))
forall a. IO (MVar a)
newEmptyMVar
let body :: IO (Either SomeException a)
body = do
ThreadId
tid <- IO () -> IO ThreadId
forkIO (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ do
Either SomeException a
r <-
forall e a. Exception e => IO a -> IO (Either e a)
Control.Exception.try @Control.Exception.SomeException (IO a -> IO (Either SomeException a))
-> IO a -> IO (Either SomeException a)
forall a b. (a -> b) -> a -> b
$
IO a -> IO a
forall a. IO a -> IO a
restore (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$
(forall (e :: Effects). IOE e -> Eff e a) -> IO a
forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff (\IOE e
_ -> Eff e a
forall (es :: Effects). Eff es a
effBody)
MVar (Either SomeException a) -> Either SomeException a -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (Either SomeException a)
done Either SomeException a
r
MVar ThreadId -> ThreadId -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar ThreadId
tidVar ThreadId
tid
MVar (Either SomeException a) -> IO (Either SomeException a)
forall a. MVar a -> IO a
takeMVar MVar (Either SomeException a)
done
Either SomeException a
r <- (IO (Either SomeException a) -> IO (Either SomeException a))
-> IO (Either SomeException a)
forall a. (a -> a) -> a
fix ((IO (Either SomeException a) -> IO (Either SomeException a))
-> IO (Either SomeException a))
-> (IO (Either SomeException a) -> IO (Either SomeException a))
-> IO (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ \IO (Either SomeException a)
again -> do
Either SomeException (Either SomeException a)
attempted <-
IO (Either SomeException (Either SomeException a))
-> IO (Either SomeException (Either SomeException a))
forall a. IO a -> IO a
restore (IO (Either SomeException (Either SomeException a))
-> IO (Either SomeException (Either SomeException a)))
-> IO (Either SomeException (Either SomeException a))
-> IO (Either SomeException (Either SomeException a))
forall a b. (a -> b) -> a -> b
$
forall e a. Exception e => IO a -> IO (Either e a)
Control.Exception.try @Control.Exception.SomeException IO (Either SomeException a)
body
case Either SomeException (Either SomeException a)
attempted of
Left SomeException
ex -> do
ThreadId
tid <- MVar ThreadId -> IO ThreadId
forall a. MVar a -> IO a
takeMVar MVar ThreadId
tidVar
ThreadId -> IO ()
killThread ThreadId
tid
Either SomeException a
_ <- MVar (Either SomeException a) -> IO (Either SomeException a)
forall a. MVar a -> IO a
takeMVar MVar (Either SomeException a)
done
ThreadId
myself <- IO ThreadId
myThreadId
ThreadId -> SomeException -> IO ()
forall e. Exception e => ThreadId -> e -> IO ()
throwTo ThreadId
myself SomeException
ex
IO (Either SomeException a)
again
Right Either SomeException a
result -> Either SomeException a -> IO (Either SomeException a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Either SomeException a
result
case Either SomeException a
r of
Left SomeException
l -> SomeException -> IO a
forall e a. Exception e => e -> IO a
Control.Exception.throwIO SomeException
l
Right a
r' -> a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
r'
unsafeCoerceEff :: Eff t r -> Eff t' r
unsafeCoerceEff :: forall (t :: Effects) r (t' :: Effects). Eff t r -> Eff t' r
unsafeCoerceEff = Eff t r -> Eff t' r
forall a b. Coercible a b => a -> b
coerce
weakenEff :: t `In` t' -> Eff t r -> Eff t' r
weakenEff :: forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (In# (# #)) = Eff t r -> Eff t' r
forall (t :: Effects) r (t' :: Effects). Eff t r -> Eff t' r
unsafeCoerceEff
insertFirst :: Eff b r -> Eff (c1 :& b) r
insertFirst :: forall (b :: Effects) r (c1 :: Effects). Eff b r -> Eff (c1 :& b) r
insertFirst = In b (c1 :& b) -> Eff b r -> Eff (c1 :& b) r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (In b b -> In b (c1 :& b)
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In a (c :& b)
drop (ZW -> In b b
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW))
insertSecond :: Eff (c1 :& b) r -> Eff (c1 :& (c2 :& b)) r
insertSecond :: forall (c1 :: Effects) (b :: Effects) r (c2 :: Effects).
Eff (c1 :& b) r -> Eff (c1 :& (c2 :& b)) r
insertSecond = Eff (c1 :& b) r -> Eff (c1 :& (c2 :& b)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
insertManySecond
insertManySecond :: (b <: c) => Eff (c1 :& b) r -> Eff (c1 :& c) r
insertManySecond :: forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
insertManySecond = In (c1 :& b) (c1 :& c) -> Eff (c1 :& b) r -> Eff (c1 :& c) r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (In c1 c1 -> In b c -> In (c1 :& b) (c1 :& c)
forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap In c1 c1
forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has In b c
forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has)
assoc1Eff :: Eff ((a :& b) :& c) r -> Eff (a :& (b :& c)) r
assoc1Eff :: forall (a :: Effects) (b :: Effects) (c :: Effects) r.
Eff ((a :& b) :& c) r -> Eff (a :& (b :& c)) r
assoc1Eff = In ((a :& b) :& c) (a :& (b :& c))
-> Eff ((a :& b) :& c) r -> Eff (a :& (b :& c)) r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (ZW -> In ((a :& b) :& c) (a :& (b :& c))
forall (a :: Effects) (b :: Effects) (c :: Effects).
ZW -> In ((a :& b) :& c) (a :& (b :& c))
assoc1 (# #) -> ZW
ZW)
pushFirst :: Eff a r -> Eff (a :& b) r
pushFirst :: forall (a :: Effects) r (b :: Effects). Eff a r -> Eff (a :& b) r
pushFirst = In a (a :& b) -> Eff a r -> Eff (a :& b) r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (ZW -> In a (a :& b)
forall (a :: Effects) (b :: Effects). ZW -> In a (a :& b)
fstI (# #) -> ZW
ZW)
mergeEff :: Eff (a :& a) r -> Eff a r
mergeEff :: forall (a :: Effects) r. Eff (a :& a) r -> Eff a r
mergeEff = In (a :& a) a -> Eff (a :& a) r -> Eff a r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (ZW -> In (a :& a) a
forall (a :: Effects). ZW -> In (a :& a) a
merge (# #) -> ZW
ZW)
inContext :: (e2 <: e1) => Eff (e1 :& e2) r -> Eff e1 r
inContext :: forall (e2 :: Effects) (e1 :: Effects) r.
(e2 <: e1) =>
Eff (e1 :& e2) r -> Eff e1 r
inContext = In (e1 :& e2) e1 -> Eff (e1 :& e2) r -> Eff e1 r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff (In e2 e1 -> In (e1 :& e2) e1
forall (e2 :: Effects) (e1 :: Effects).
In e2 e1 -> In (e1 :& e2) e1
subsume1 In e2 e1
forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has)
makeOp :: Eff (e :& e) r -> Eff e r
makeOp :: forall (a :: Effects) r. Eff (a :& a) r -> Eff a r
makeOp = Eff (e :& e) r -> Eff e r
forall (e2 :: Effects) (e1 :: Effects) r.
(e2 <: e1) =>
Eff (e1 :& e2) r -> Eff e1 r
inContext
useImpl :: (e <: es) => Eff e r -> Eff es r
useImpl :: forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl = In e es -> Eff e r -> Eff es r
forall (t :: Effects) (t' :: Effects) r.
In t t' -> Eff t r -> Eff t' r
weakenEff In e es
forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has
useImplUnder ::
(e <: es) =>
Eff (e1 :& e) r ->
Eff (e1 :& es) r
useImplUnder :: forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder = Eff (e1 :& e) r -> Eff (e1 :& es) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
insertManySecond
useImplIn ::
(e <: es) =>
(t -> Eff (es :& e) r) ->
t ->
Eff es r
useImplIn :: forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn t -> Eff (es :& e) r
f t
h = Eff (es :& e) r -> Eff es r
forall (e2 :: Effects) (e1 :: Effects) r.
(e2 <: e1) =>
Eff (e1 :& e2) r -> Eff e1 r
inContext (t -> Eff (es :& e) r
f t
h)
useImplWithin ::
(e <: es) =>
(t -> Eff (e1 :& e) r) ->
t ->
Eff (e1 :& es) r
useImplWithin :: forall (e :: Effects) (es :: Effects) t (e1 :: Effects) r.
(e <: es) =>
(t -> Eff (e1 :& e) r) -> t -> Eff (e1 :& es) r
useImplWithin t -> Eff (e1 :& e) r
k = Eff (e1 :& e) r -> Eff (e1 :& es) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& e) r -> Eff (e1 :& es) r)
-> (t -> Eff (e1 :& e) r) -> t -> Eff (e1 :& es) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Eff (e1 :& e) r
k
data StateSource (e :: Effects) = StateSource
type role StateSource nominal
newtype Throw exn (e :: Effects)
= MkException (forall a. exn -> Eff e a)
deriving (HandleD (Throw exn)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Throw exn e) (Throw exn es)) =>
HandleD (Throw exn) -> Handle (Throw exn)
forall exn. HandleD (Throw exn)
forall exn (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Throw exn e) (Throw exn es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Throw exn e) (Throw exn es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall exn. HandleD (Throw exn)
handleImpl :: HandleD (Throw exn)
Handle) via OneWayCoercibleHandle (Throw exn)
type role Throw representational nominal
instance (e <: es) => OneWayCoercible (Throw ex e) (Throw ex es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Throw ex e) (Throw ex es)
oneWayCoercibleImpl = OneWayCoercibleD (Throw ex e) (Throw ex es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
type ThrowCatch :: Type -> Effects -> Type
newtype ThrowCatch ex e
= MkThrowCatch (ScopedException.Exception ex)
deriving (HandleD (ThrowCatch ex)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ThrowCatch ex e) (ThrowCatch ex es)) =>
HandleD (ThrowCatch ex) -> Handle (ThrowCatch ex)
forall ex. HandleD (ThrowCatch ex)
forall ex (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ThrowCatch ex e) (ThrowCatch ex es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ThrowCatch ex e) (ThrowCatch ex es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall ex. HandleD (ThrowCatch ex)
handleImpl :: HandleD (ThrowCatch ex)
Handle) via OneWayCoercibleHandle (ThrowCatch ex)
type role ThrowCatch nominal nominal
instance
(e <: es) =>
OneWayCoercible (ThrowCatch ex e) (ThrowCatch ex es)
where
oneWayCoercibleImpl :: OneWayCoercibleD (ThrowCatch ex e) (ThrowCatch ex es)
oneWayCoercibleImpl = OneWayCoercibleD (ThrowCatch ex e) (ThrowCatch ex es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
newtype Modify s (e :: Effects) = UnsafeMkState (IORef s)
deriving (HandleD (Modify s)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Modify s e) (Modify s es)) =>
HandleD (Modify s) -> Handle (Modify s)
forall s. HandleD (Modify s)
forall s (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Modify s e) (Modify s es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Modify s e) (Modify s es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall s. HandleD (Modify s)
handleImpl :: HandleD (Modify s)
Handle) via OneWayCoercibleHandle (Modify s)
type role Modify representational nominal
instance (e <: es) => OneWayCoercible (Modify s e) (Modify s es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Modify s e) (Modify s es)
oneWayCoercibleImpl = OneWayCoercibleD (Modify s e) (Modify s es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
newtype Request a b (e :: Effects) = MkCoroutine (a -> Eff e b)
deriving (HandleD (Request a b)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Request a b e) (Request a b es)) =>
HandleD (Request a b) -> Handle (Request a b)
forall a b. HandleD (Request a b)
forall a b (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Request a b e) (Request a b es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Request a b e) (Request a b es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall a b. HandleD (Request a b)
handleImpl :: HandleD (Request a b)
Handle) via OneWayCoercibleHandle (Request a b)
instance (e <: es) => OneWayCoercible (Request a b e) (Request a b es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Request a b e) (Request a b es)
oneWayCoercibleImpl = OneWayCoercibleD (Request a b e) (Request a b es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
type Yield a = Request a ()
type Await a = Request () a
class
(forall e es. (e <: es) => OneWayCoercible (h e) (h es)) =>
Handle (h :: Effects -> Type)
where
handleImpl :: HandleD h
mapHandle :: forall h e es. (Handle h, e <: es) => h e -> h es
mapHandle :: forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle = h e -> h es
forall a b. OneWayCoercible a b => a -> b
unsafeOneWayCoerce
withHandle ::
forall h r.
(Handle h) =>
((forall e es. (e <: es) => OneWayCoercible (h e) (h es)) => r) ->
r
withHandle :: forall (h :: Effects -> *) r.
Handle h =>
((forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
r)
-> r
withHandle (forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
r
r = r
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
r
r
type HandleDict :: (Effects -> Type) -> Type
data HandleDict h where
MkHandleDict ::
(forall e es. (e <: es) => OneWayCoercible (h e) (h es)) =>
HandleDict h
type role HandleDict nominal
type HandleD :: (Effects -> Type) -> Type
newtype HandleD h = MkHandleD (HandleDict Any)
handleDictOfHandleD :: HandleD h -> HandleDict h
handleDictOfHandleD :: forall (h :: Effects -> *). HandleD h -> HandleDict h
handleDictOfHandleD (MkHandleD HandleDict Any
f) = HandleDict Any -> HandleDict h
forall a b. a -> b
unsafeCoerce HandleDict Any
f
handleDictImpl :: (Handle h) => HandleDict h
handleDictImpl :: forall (h :: Effects -> *). Handle h => HandleDict h
handleDictImpl = HandleD h -> HandleDict h
forall (h :: Effects -> *). HandleD h -> HandleDict h
handleDictOfHandleD HandleD h
forall (h :: Effects -> *). Handle h => HandleD h
handleImpl
type role HandleD representational
handleOneWayCoercible ::
forall h.
(forall e es. (e <: es) => OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible :: forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible = HandleDict Any -> HandleD h
forall (h :: Effects -> *). HandleDict Any -> HandleD h
MkHandleD (HandleDict h -> HandleDict Any
forall a b. a -> b
unsafeCoerce (forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleDict h
MkHandleDict @h))
instance (Handle h) => Handle (Rec1 h) where
handleImpl :: HandleD (Rec1 h)
handleImpl = HandleD (Rec1 h)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible
instance (Handle h) => Handle (M1 i t h) where
handleImpl :: HandleD (M1 i t h)
handleImpl = HandleD (M1 i t h)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible
instance (Handle h1, Handle h2) => Handle (h1 :*: h2) where
handleImpl :: HandleD (h1 :*: h2)
handleImpl = HandleD (h1 :*: h2)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible
oneWayCoercibleTrustMe ::
(e <: es) =>
(forall e' es'. (e' <: es') => h e' -> h es') ->
OneWayCoercibleD (h e) (h es)
oneWayCoercibleTrustMe :: forall (e :: Effects) (es :: Effects) (h :: Effects -> *).
(e <: es) =>
(forall (e' :: Effects) (es' :: Effects).
(e' <: es') =>
h e' -> h es')
-> OneWayCoercibleD (h e) (h es)
oneWayCoercibleTrustMe !forall (e' :: Effects) (es' :: Effects).
(e' <: es') =>
h e' -> h es'
_ = OneWayCoercibleD (h e) (h es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
newtype OneWayCoercibleHandle a es = MkOneWayCoercibleHandle (a es)
deriving stock ((forall x.
OneWayCoercibleHandle a es -> Rep (OneWayCoercibleHandle a es) x)
-> (forall x.
Rep (OneWayCoercibleHandle a es) x -> OneWayCoercibleHandle a es)
-> Generic (OneWayCoercibleHandle a es)
forall x.
Rep (OneWayCoercibleHandle a es) x -> OneWayCoercibleHandle a es
forall x.
OneWayCoercibleHandle a es -> Rep (OneWayCoercibleHandle a es) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (a :: k -> *) (es :: k) x.
Rep (OneWayCoercibleHandle a es) x -> OneWayCoercibleHandle a es
forall k (a :: k -> *) (es :: k) x.
OneWayCoercibleHandle a es -> Rep (OneWayCoercibleHandle a es) x
$cfrom :: forall k (a :: k -> *) (es :: k) x.
OneWayCoercibleHandle a es -> Rep (OneWayCoercibleHandle a es) x
from :: forall x.
OneWayCoercibleHandle a es -> Rep (OneWayCoercibleHandle a es) x
$cto :: forall k (a :: k -> *) (es :: k) x.
Rep (OneWayCoercibleHandle a es) x -> OneWayCoercibleHandle a es
to :: forall x.
Rep (OneWayCoercibleHandle a es) x -> OneWayCoercibleHandle a es
Generic)
instance
forall h.
(forall e' es'. (e' <: es') => OneWayCoercible (OneWayCoercibleHandle h e') (OneWayCoercibleHandle h es')) =>
Handle (OneWayCoercibleHandle h)
where
handleImpl :: HandleD (OneWayCoercibleHandle h)
handleImpl = HandleD (OneWayCoercibleHandle h)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h
handleOneWayCoercible
instance
(OneWayCoercible (h e) (h es)) =>
OneWayCoercible (OneWayCoercibleHandle h e) (OneWayCoercibleHandle h es)
where
oneWayCoercibleImpl :: OneWayCoercibleD
(OneWayCoercibleHandle h e) (OneWayCoercibleHandle h es)
oneWayCoercibleImpl = OneWayCoercibleD
(OneWayCoercibleHandle h e) (OneWayCoercibleHandle h es)
forall {k} (h :: k -> *) (e :: k) (es :: k).
GOneWayCoercible (Rep (h e)) (Rep (h es)) =>
OneWayCoercibleD (h e) (h es)
gOneWayCoercible
oneWayCoercibleNewtypeHandle ::
forall h1 h2 e es.
(e :> es) =>
( Coercible (h2 e) (h1 e),
OneWayCoercible (h1 e) (h1 es),
Coercible (h1 es) (h2 es)
) =>
OneWayCoercibleD (h2 e) (h2 es)
oneWayCoercibleNewtypeHandle :: forall {k} (h1 :: Effects -> k) (h2 :: Effects -> k) (e :: Effects)
(es :: Effects).
(e :> es, Coercible (h2 e) (h1 e), OneWayCoercible (h1 e) (h1 es),
Coercible (h1 es) (h2 es)) =>
OneWayCoercibleD (h2 e) (h2 es)
oneWayCoercibleNewtypeHandle =
OneWayCoercibleD (h2 e) (h1 e)
-> OneWayCoercibleD (h1 e) (h1 es)
-> OneWayCoercibleD (h1 es) (h2 es)
-> OneWayCoercibleD (h2 e) (h2 es)
forall {k} (t1 :: k) (t2 :: k) (t3 :: k) (t4 :: k).
OneWayCoercibleD t1 t2
-> OneWayCoercibleD t2 t3
-> OneWayCoercibleD t3 t4
-> OneWayCoercibleD t1 t4
trans3D
(forall (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible @(h2 e) @(h1 e))
(forall (a :: k) (b :: k).
OneWayCoercible a b =>
OneWayCoercibleD a b
forall {k} (a :: k) (b :: k).
OneWayCoercible a b =>
OneWayCoercibleD a b
oneWayCoercibleImpl @(h1 e) @(h1 es))
(forall (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible @(h1 es) @(h2 es))
newtype ZW = MkZW (# #)
pattern ZW :: ZW
pattern $mZW :: forall {r}. ZW -> ((# #) -> r) -> ((# #) -> r) -> r
$bZW :: (# #) -> ZW
ZW <- MkZW (# #)
where
ZW = (# #) -> ZW
MkZW (# #)
{-# COMPLETE ZW #-}
newtype In (a :: Effects) (b :: Effects) = In# (# #)
unsafeInAxiom :: ZW -> e1 `In` e2
unsafeInAxiom :: forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom ZW
ZW = (# #) -> In e1 e2
forall (a :: Effects) (b :: Effects). (# #) -> In a b
In# (# #)
merge :: ZW -> (a :& a) `In` a
merge :: forall (a :: Effects). ZW -> In (a :& a) a
merge ZW
ZW = (# #) -> In (a :& a) a
forall (a :: Effects) (b :: Effects). (# #) -> In a b
In# (# #)
eq :: ZW -> a `In` a
eq :: forall (a :: Effects). ZW -> In a a
eq ZW
ZW = ZW -> In a a
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
fstI :: ZW -> a `In` (a :& b)
fstI :: forall (a :: Effects) (b :: Effects). ZW -> In a (a :& b)
fstI ZW
ZW = ZW -> In a (a :& b)
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
sndI :: ZW -> a `In` (b :& a)
sndI :: forall (a :: Effects) (b :: Effects). ZW -> In a (b :& a)
sndI ZW
ZW = ZW -> In a (b :& a)
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
cmp :: a `In` b -> b `In` c -> a `In` c
cmp :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (In# (# #)) (In# (# #)) = ZW -> In a c
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
bimap :: a `In` b -> c `In` d -> (a :& c) `In` (b :& d)
bimap :: forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap (In# (# #)) (In# (# #)) = ZW -> In (a :& c) (b :& d)
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
assoc1 :: ZW -> ((a :& b) :& c) `In` (a :& (b :& c))
assoc1 :: forall (a :: Effects) (b :: Effects) (c :: Effects).
ZW -> In ((a :& b) :& c) (a :& (b :& c))
assoc1 ZW
ZW = ZW -> In ((a :& b) :& c) (a :& (b :& c))
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
drop :: a `In` b -> a `In` (c :& b)
drop :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In a (c :& b)
drop In a b
h = In (c :& a) (c :& b) -> In a (c :& b)
forall (b :: Effects) (a :: Effects) (c :: Effects).
In (b :& a) c -> In a c
w2 (In a b -> In (c :& a) (c :& b)
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In (c :& a) (c :& b)
b In a b
h)
here :: a `In` b -> (a `In` (b :& c))
here :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In a (b :& c)
here In a b
h = In (a :& c) (b :& c) -> In a (b :& c)
forall (a :: Effects) (b :: Effects) (c :: Effects).
In (a :& b) c -> In a c
w (In a b -> In (a :& c) (b :& c)
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In (a :& c) (b :& c)
b2 In a b
h)
w :: (a :& b) `In` c -> (a `In` c)
w :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In (a :& b) c -> In a c
w = In a (a :& b) -> In (a :& b) c -> In a c
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (ZW -> In a (a :& b)
forall (a :: Effects) (b :: Effects). ZW -> In a (a :& b)
fstI (# #) -> ZW
ZW)
w2 :: (b :& a) `In` c -> (a `In` c)
w2 :: forall (b :: Effects) (a :: Effects) (c :: Effects).
In (b :& a) c -> In a c
w2 = In a (b :& a) -> In (b :& a) c -> In a c
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (ZW -> In a (b :& a)
forall (a :: Effects) (b :: Effects). ZW -> In a (b :& a)
sndI (# #) -> ZW
ZW)
b2 :: (a `In` b) -> ((a :& c) `In` (b :& c))
b2 :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In (a :& c) (b :& c)
b2 In a b
h = In a b -> In c c -> In (a :& c) (b :& c)
forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap In a b
h (ZW -> In c c
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW)
b :: (a `In` b) -> (c :& a) `In` (c :& b)
b :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In (c :& a) (c :& b)
b = In c c -> In a b -> In (c :& a) (c :& b)
forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap (ZW -> In c c
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW)
subsume1 :: (e2 `In` e1) -> (e1 :& e2) `In` e1
subsume1 :: forall (e2 :: Effects) (e1 :: Effects).
In e2 e1 -> In (e1 :& e2) e1
subsume1 In e2 e1
i = In (e1 :& e2) (e1 :& e1) -> In (e1 :& e1) e1 -> In (e1 :& e2) e1
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (In e1 e1 -> In e2 e1 -> In (e1 :& e2) (e1 :& e1)
forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap (ZW -> In e1 e1
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW) In e2 e1
i) (ZW -> In (e1 :& e1) e1
forall (a :: Effects). ZW -> In (a :& a) a
merge (# #) -> ZW
ZW)
subsume2 :: (e1 `In` e2) -> (e1 :& e2) `In` e2
subsume2 :: forall (e1 :: Effects) (e2 :: Effects).
In e1 e2 -> In (e1 :& e2) e2
subsume2 In e1 e2
i = In (e1 :& e2) (e2 :& e2) -> In (e2 :& e2) e2 -> In (e1 :& e2) e2
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (In e1 e2 -> In e2 e2 -> In (e1 :& e2) (e2 :& e2)
forall (a :: Effects) (b :: Effects) (c :: Effects) (d :: Effects).
In a b -> In c d -> In (a :& c) (b :& d)
bimap In e1 e2
i (ZW -> In e2 e2
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW)) (ZW -> In (e2 :& e2) e2
forall (a :: Effects). ZW -> In (a :& a) a
merge (# #) -> ZW
ZW)
class (es1 :: Effects) :> (es2 :: Effects)
type (<:) = (:>)
instance e :> e
instanceProof1 :: ZW -> e `In` e
instanceProof1 :: forall (a :: Effects). ZW -> In a a
instanceProof1 ZW
ZW = ZW -> In e e
forall (a :: Effects). ZW -> In a a
eq (# #) -> ZW
ZW
instance {-# INCOHERENT #-} (e :> es) => e :> (x :& es)
instanceProof2 :: e `In` es -> e `In` (x :& es)
instanceProof2 :: forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In a (c :& b)
instanceProof2 = In e es -> In e (x :& es)
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In a (c :& b)
drop
instance e :> (e :& es)
instanceProof3 :: ZW -> e `In` (e :& es)
instanceProof3 :: forall (a :: Effects) (b :: Effects). ZW -> In a (a :& b)
instanceProof3 ZW
ZW = ZW -> In e (e :& es)
forall (a :: Effects) (b :: Effects). ZW -> In a (a :& b)
fstI (# #) -> ZW
ZW
subset ::
forall e1 es m.
(Monad m) =>
(e1 <: es) =>
m ()
subset :: forall (e1 :: Effects) (es :: Effects) (m :: * -> *).
(Monad m, e1 <: es) =>
m ()
subset = forall (c :: Constraint) (m :: * -> *). (Monad m, c) => m ()
satisfied @(e1 <: es)
satisfied :: forall c m. (Monad m, c) => m ()
satisfied :: forall (c :: Constraint) (m :: * -> *). (Monad m, c) => m ()
satisfied = () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
effTag :: Eff es (Proxy es)
effTag :: forall (es :: Effects). Eff es (Proxy es)
effTag = Proxy es -> Eff es (Proxy es)
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy es
forall {k} (t :: k). Proxy t
Proxy
handleTag :: h e -> Eff es (Proxy e)
handleTag :: forall {k} (h :: k -> *) (e :: k) (es :: Effects).
h e -> Eff es (Proxy e)
handleTag h e
_ = Proxy e -> Eff es (Proxy e)
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy e
forall {k} (t :: k). Proxy t
Proxy
throw ::
(e <: es) =>
Throw ex e ->
ex ->
Eff es a
throw :: forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
throw Throw ex e
h = case Throw ex e -> Throw ex es
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle Throw ex e
h of MkException forall a. ex -> Eff es a
throw_ -> ex -> Eff es a
forall a. ex -> Eff es a
throw_
throwCatchThrow ::
(e <: es) =>
ThrowCatch ex e ->
ex ->
Eff es a
throwCatchThrow :: forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
ThrowCatch ex e -> ex -> Eff es a
throwCatchThrow (MkThrowCatch Exception ex
ex) ex
exn =
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> IOE e -> IO a -> Eff (e :& es) a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io (Exception ex -> ex -> IO a
forall e a. Exception e -> e -> IO a
ScopedException.throw Exception ex
ex ex
exn)
has :: forall a b. (a <: b) => a `In` b
has :: forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has = ZW -> In a b
forall (e1 :: Effects) (e2 :: Effects). ZW -> In e1 e2
unsafeInAxiom (# #) -> ZW
ZW
data Dict c where
Dict :: forall c. (c) => Dict c
unsafeCoerceDict :: forall c c'. Dict c -> Dict c'
unsafeCoerceDict :: forall (c :: Constraint) (c' :: Constraint). Dict c -> Dict c'
unsafeCoerceDict = forall a b. a -> b
unsafeCoerce @(Dict c) @(Dict c')
have :: forall a b. a `In` b -> Dict (a <: b)
have :: forall (a :: Effects) (b :: Effects). In a b -> Dict (a <: b)
have In a b
_ = forall (c :: Constraint) (c' :: Constraint). Dict c -> Dict c'
unsafeCoerceDict @(a <: (a :& b)) @(a <: b) Dict (a <: (a :& b))
forall (c :: Constraint). c => Dict c
Dict
try ::
forall exn (es :: Effects) a.
(forall e. Throw exn e -> Eff (e :& es) a) ->
Eff es (Either exn a)
try :: forall exn (es :: Effects) a.
(forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es (Either exn a)
try forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f =
(forall (e :: Effects). ThrowCatch exn e -> Eff (e :& es) a)
-> Eff es (Either exn a)
forall ex (es :: Effects) a.
(forall (e :: Effects). ThrowCatch ex e -> Eff (e :& es) a)
-> Eff es (Either ex a)
throwCatchTry ((forall (e :: Effects). ThrowCatch exn e -> Eff (e :& es) a)
-> Eff es (Either exn a))
-> (forall (e :: Effects). ThrowCatch exn e -> Eff (e :& es) a)
-> Eff es (Either exn a)
forall a b. (a -> b) -> a -> b
$ \ThrowCatch exn e
ex ->
Throw exn e -> Eff (e :& es) a
forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f ((forall a. exn -> Eff e a) -> Throw exn e
forall exn (e :: Effects).
(forall a. exn -> Eff e a) -> Throw exn e
MkException (ThrowCatch exn e -> exn -> Eff e a
forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
ThrowCatch ex e -> ex -> Eff es a
throwCatchThrow ThrowCatch exn e
ex))
throwCatchTry ::
(forall e. ThrowCatch ex e -> Eff (e :& es) a) ->
Eff es (Either ex a)
throwCatchTry :: forall ex (es :: Effects) a.
(forall (e :: Effects). ThrowCatch ex e -> Eff (e :& es) a)
-> Eff es (Either ex a)
throwCatchTry forall (e :: Effects). ThrowCatch ex e -> Eff (e :& es) a
f =
(forall (e :: Effects). IOE e -> Eff (e :& es) (Either ex a))
-> Eff es (Either ex a)
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) (Either ex a))
-> Eff es (Either ex a))
-> (forall (e :: Effects). IOE e -> Eff (e :& es) (Either ex a))
-> Eff es (Either ex a)
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
IOE e
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO (Either ex a))
-> Eff (e :& es) (Either ex a)
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e
io (((forall {r}. Eff (e :& es) r -> IO r) -> IO (Either ex a))
-> Eff (e :& es) (Either ex a))
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO (Either ex a))
-> Eff (e :& es) (Either ex a)
forall a b. (a -> b) -> a -> b
$ \forall {r}. Eff (e :& es) r -> IO r
effToIO -> do
(Exception ex -> IO a) -> IO (Either ex a)
forall e a. (Exception e -> IO a) -> IO (Either e a)
ScopedException.try ((Exception ex -> IO a) -> IO (Either ex a))
-> (Exception ex -> IO a) -> IO (Either ex a)
forall a b. (a -> b) -> a -> b
$ \Exception ex
ex -> do
Eff (e :& es) a -> IO a
forall {r}. Eff (e :& es) r -> IO r
effToIO (ThrowCatch ex e -> Eff (e :& es) a
forall (e :: Effects). ThrowCatch ex e -> Eff (e :& es) a
f (Exception ex -> ThrowCatch ex e
forall ex (e :: Effects). Exception ex -> ThrowCatch ex e
MkThrowCatch Exception ex
ex))
handle ::
forall exn (es :: Effects) a.
(exn -> Eff es a) ->
(forall e. Throw exn e -> Eff (e :& es) a) ->
Eff es a
handle :: forall exn (es :: Effects) a.
(exn -> Eff es a)
-> (forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es a
handle exn -> Eff es a
h forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f =
(forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es (Either exn a)
forall exn (es :: Effects) a.
(forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es (Either exn a)
try Throw exn e -> Eff (e :& es) a
forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f Eff es (Either exn a) -> (Either exn a -> Eff es a) -> Eff es a
forall a b. Eff es a -> (a -> Eff es b) -> Eff es b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left exn
e -> exn -> Eff es a
h exn
e
Right a
a -> a -> Eff es a
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
catch ::
forall exn (es :: Effects) a.
(forall e. Throw exn e -> Eff (e :& es) a) ->
(exn -> Eff es a) ->
Eff es a
catch :: forall exn (es :: Effects) a.
(forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> (exn -> Eff es a) -> Eff es a
catch forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f exn -> Eff es a
h = (exn -> Eff es a)
-> (forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es a
forall exn (es :: Effects) a.
(exn -> Eff es a)
-> (forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es a
handle exn -> Eff es a
h Throw exn e -> Eff (e :& es) a
forall (e :: Effects). Throw exn e -> Eff (e :& es) a
f
rethrowIO ::
forall ex es e1 e2 r.
(e1 <: es, e2 <: es, Control.Exception.Exception ex) =>
IOE e1 ->
Throw ex e2 ->
Eff es r ->
Eff es r
rethrowIO :: forall ex (es :: Effects) (e1 :: Effects) (e2 :: Effects) r.
(e1 <: es, e2 <: es, Exception ex) =>
IOE e1 -> Throw ex e2 -> Eff es r -> Eff es r
rethrowIO IOE e1
io Throw ex e2
ex Eff es r
body =
IOE e1 -> ((forall {r}. Eff es r -> IO r) -> IO r) -> Eff es r
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e1
io (((forall {r}. Eff es r -> IO r) -> IO r) -> Eff es r)
-> ((forall {r}. Eff es r -> IO r) -> IO r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \forall {r}. Eff es r -> IO r
effToIO -> do
IO r -> (ex -> IO r) -> IO r
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
Control.Exception.catch
(Eff es r -> IO r
forall {r}. Eff es r -> IO r
effToIO Eff es r
body)
(\ex
e -> Eff es r -> IO r
forall {r}. Eff es r -> IO r
effToIO (forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
throw @_ @es Throw ex e2
ex ex
e))
bracket ::
Eff es a ->
(a -> Eff es ()) ->
(a -> Eff es b) ->
Eff es b
bracket :: forall (es :: Effects) a b.
Eff es a -> (a -> Eff es ()) -> (a -> Eff es b) -> Eff es b
bracket Eff es a
before a -> Eff es ()
after a -> Eff es b
body =
(forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
IOE e
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e
io (((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b)
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b
forall a b. (a -> b) -> a -> b
$ \forall {r}. Eff (e :& es) r -> IO r
effToIO -> do
IO a -> (a -> IO ()) -> (a -> IO b) -> IO b
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
Control.Exception.bracket
(Eff (e :& es) a -> IO a
forall {r}. Eff (e :& es) r -> IO r
effToIO (Eff es a -> Eff (e :& es) a
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl Eff es a
before))
(Eff (e :& es) () -> IO ()
forall {r}. Eff (e :& es) r -> IO r
effToIO (Eff (e :& es) () -> IO ())
-> (a -> Eff (e :& es) ()) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es () -> Eff (e :& es) ()
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl (Eff es () -> Eff (e :& es) ())
-> (a -> Eff es ()) -> a -> Eff (e :& es) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Eff es ()
after)
(Eff (e :& es) b -> IO b
forall {r}. Eff (e :& es) r -> IO r
effToIO (Eff (e :& es) b -> IO b) -> (a -> Eff (e :& es) b) -> a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es b -> Eff (e :& es) b
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl (Eff es b -> Eff (e :& es) b)
-> (a -> Eff es b) -> a -> Eff (e :& es) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Eff es b
body)
finally ::
Eff es b ->
Eff es () ->
Eff es b
finally :: forall (es :: Effects) b. Eff es b -> Eff es () -> Eff es b
finally Eff es b
body Eff es ()
after =
(forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) b) -> Eff es b
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
IOE e
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
withEffToIO_ IOE e
io (((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b)
-> ((forall {r}. Eff (e :& es) r -> IO r) -> IO b)
-> Eff (e :& es) b
forall a b. (a -> b) -> a -> b
$ \forall {r}. Eff (e :& es) r -> IO r
effToIO -> do
IO b -> IO () -> IO b
forall a b. IO a -> IO b -> IO a
Control.Exception.finally
(Eff (e :& es) b -> IO b
forall {r}. Eff (e :& es) r -> IO r
effToIO (Eff es b -> Eff (e :& es) b
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl Eff es b
body))
(Eff (e :& es) () -> IO ()
forall {r}. Eff (e :& es) r -> IO r
effToIO (Eff es () -> Eff (e :& es) ()
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl Eff es ()
after))
withStateInIO ::
(e1 <: es, e2 <: es) =>
IOE e1 ->
Modify s e2 ->
(IORef s -> IO r) ->
Eff es r
withStateInIO :: forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) s r.
(e1 <: es, e2 <: es) =>
IOE e1 -> Modify s e2 -> (IORef s -> IO r) -> Eff es r
withStateInIO IOE e1
io (UnsafeMkState IORef s
r) IORef s -> IO r
k = IOE e1 -> IO r -> Eff es r
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e1
io (IORef s -> IO r
k IORef s
r)
get ::
(e <: es) =>
Modify s e ->
Eff es s
get :: forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify s e
st = (forall (e :: Effects). IOE e -> Eff (e :& es) s) -> Eff es s
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) s) -> Eff es s)
-> (forall (e :: Effects). IOE e -> Eff (e :& es) s) -> Eff es s
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> IOE e -> Modify s e -> (IORef s -> IO s) -> Eff (e :& es) s
forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) s r.
(e1 <: es, e2 <: es) =>
IOE e1 -> Modify s e2 -> (IORef s -> IO r) -> Eff es r
withStateInIO IOE e
io Modify s e
st IORef s -> IO s
forall a. IORef a -> IO a
readIORef
put ::
(e <: es) =>
Modify s e ->
s ->
Eff es ()
put :: forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> s -> Eff es ()
put Modify s e
st s
s = (forall (e :: Effects). IOE e -> Eff (e :& es) ()) -> Eff es ()
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) ()) -> Eff es ())
-> (forall (e :: Effects). IOE e -> Eff (e :& es) ()) -> Eff es ()
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> IOE e -> Modify s e -> (IORef s -> IO ()) -> Eff (e :& es) ()
forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) s r.
(e1 <: es, e2 <: es) =>
IOE e1 -> Modify s e2 -> (IORef s -> IO r) -> Eff es r
withStateInIO IOE e
io Modify s e
st ((IORef s -> s -> IO ()) -> s -> IORef s -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip IORef s -> s -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef (s -> IORef s -> IO ()) -> s -> IORef s -> IO ()
forall a b. (a -> b) -> a -> b
$! s
s)
modify ::
(e <: es) =>
Modify s e ->
(s -> s) ->
Eff es ()
modify :: forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> (s -> s) -> Eff es ()
modify Modify s e
state s -> s
f = do
s
s <- Modify s e -> Eff es s
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify s e
state
Modify s e -> s -> Eff es ()
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> s -> Eff es ()
put Modify s e
state (s -> s
f s
s)
withStateSource ::
(forall e. StateSource e -> Eff (e :& es) a) ->
Eff es a
withStateSource :: forall (es :: Effects) a.
(forall (e :: Effects). StateSource e -> Eff (e :& es) a)
-> Eff es a
withStateSource forall (e :: Effects). StateSource e -> Eff (e :& es) a
f = (StateSource es -> Eff (es :& es) a) -> StateSource es -> Eff es a
forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn StateSource es -> Eff (es :& es) a
forall (e :: Effects). StateSource e -> Eff (e :& es) a
f StateSource es
forall (e :: Effects). StateSource e
StateSource
newState ::
(e <: es) =>
StateSource e ->
s ->
Eff es (Modify s e)
newState :: forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
StateSource e -> s -> Eff es (Modify s e)
newState StateSource e
StateSource s
s = (forall (e :: Effects). IOE e -> Eff (e :& es) (Modify s e))
-> Eff es (Modify s e)
forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO ((forall (e :: Effects). IOE e -> Eff (e :& es) (Modify s e))
-> Eff es (Modify s e))
-> (forall (e :: Effects). IOE e -> Eff (e :& es) (Modify s e))
-> Eff es (Modify s e)
forall a b. (a -> b) -> a -> b
$ \IOE e
io -> do
(IORef s -> Modify s e)
-> Eff (e :& es) (IORef s) -> Eff (e :& es) (Modify s e)
forall a b. (a -> b) -> Eff (e :& es) a -> Eff (e :& es) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IORef s -> Modify s e
forall s (e :: Effects). IORef s -> Modify s e
UnsafeMkState (IOE e -> IO (IORef s) -> Eff (e :& es) (IORef s)
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
io (s -> IO (IORef s)
forall a. a -> IO (IORef a)
newIORef s
s))
runState ::
s ->
(forall e. Modify s e -> Eff (e :& es) a) ->
Eff es (a, s)
runState :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runState s
s forall (e :: Effects). Modify s e -> Eff (e :& es) a
f = do
(forall (e :: Effects). StateSource e -> Eff (e :& es) (a, s))
-> Eff es (a, s)
forall (es :: Effects) a.
(forall (e :: Effects). StateSource e -> Eff (e :& es) a)
-> Eff es a
withStateSource ((forall (e :: Effects). StateSource e -> Eff (e :& es) (a, s))
-> Eff es (a, s))
-> (forall (e :: Effects). StateSource e -> Eff (e :& es) (a, s))
-> Eff es (a, s)
forall a b. (a -> b) -> a -> b
$ \StateSource e
source -> do
Modify s e
state <- StateSource e -> s -> Eff (e :& es) (Modify s e)
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
StateSource e -> s -> Eff es (Modify s e)
newState StateSource e
source s
s
a
a <- Modify s e -> Eff (e :& es) a
forall (e :: Effects). Modify s e -> Eff (e :& es) a
f Modify s e
state
s
s' <- Modify s e -> Eff (e :& es) s
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify s e
state
(a, s) -> Eff (e :& es) (a, s)
forall a. a -> Eff (e :& es) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a, s
s')
yieldCoroutine ::
(e1 <: es) =>
Coroutine a b e1 ->
a ->
Eff es b
yieldCoroutine :: forall (e1 :: Effects) (es :: Effects) a b.
(e1 <: es) =>
Coroutine a b e1 -> a -> Eff es b
yieldCoroutine (MkCoroutine a -> Eff e1 b
f) = Eff e1 b -> Eff es b
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl (Eff e1 b -> Eff es b) -> (a -> Eff e1 b) -> a -> Eff es b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Eff e1 b
f
yield ::
(e1 <: es) =>
Yield a e1 ->
a ->
Eff es ()
yield :: forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield = Coroutine a () e1 -> a -> Eff es ()
forall (e1 :: Effects) (es :: Effects) a b.
(e1 <: es) =>
Coroutine a b e1 -> a -> Eff es b
yieldCoroutine
handleCoroutine ::
(a -> Eff es b) ->
(z -> Eff es r) ->
(forall e1. Coroutine a b e1 -> Eff (e1 :& es) z) ->
Eff es r
handleCoroutine :: forall a (es :: Effects) b z r.
(a -> Eff es b)
-> (z -> Eff es r)
-> (forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) z)
-> Eff es r
handleCoroutine a -> Eff es b
update z -> Eff es r
finish forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) z
f = do
z
z <- (forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) z)
-> (a -> Eff es b) -> Eff es z
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach Coroutine a b e1 -> Eff (e1 :& es) z
forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) z
f a -> Eff es b
update
z -> Eff es r
finish z
z
forEach ::
(forall e1. Request a b e1 -> Eff (e1 :& es) r) ->
(a -> Eff es b) ->
Eff es r
forEach :: forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r
f a -> Eff es b
h = (Request a b es -> Eff (es :& es) r) -> Request a b es -> Eff es r
forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn Request a b es -> Eff (es :& es) r
forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r
f ((a -> Eff es b) -> Request a b es
forall a b (e :: Effects). (a -> Eff e b) -> Request a b e
MkCoroutine a -> Eff es b
h)
ignoreStream ::
(forall e1. Stream a e1 -> Eff (e1 :& es) r) ->
Eff es r
ignoreStream :: forall a (es :: Effects) r.
(forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r)
-> Eff es r
ignoreStream forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r
k = (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r)
-> (a -> Eff es ()) -> Eff es r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach Stream a e1 -> Eff (e1 :& es) r
forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r
k (\a
_ -> () -> Eff es ()
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
inFoldable ::
(Foldable t, e1 <: es) =>
t a ->
Yield a e1 ->
Eff es ()
inFoldable :: forall (t :: * -> *) (e1 :: Effects) (es :: Effects) a.
(Foldable t, e1 <: es) =>
t a -> Yield a e1 -> Eff es ()
inFoldable t a
t = t a -> (a -> Eff es ()) -> Eff es ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ t a
t ((a -> Eff es ()) -> Eff es ())
-> (Yield a e1 -> a -> Eff es ()) -> Yield a e1 -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Yield a e1 -> a -> Eff es ()
forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield
enumerate ::
(e2 <: es) =>
(forall e1. Yield a e1 -> Eff (e1 :& es) r) ->
Yield (Int, a) e2 ->
Eff es r
enumerate :: forall (e2 :: Effects) (es :: Effects) a r.
(e2 <: es) =>
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield (Int, a) e2 -> Eff es r
enumerate forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
s = Int
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield (Int, a) e2
-> Eff es r
forall (e2 :: Effects) (es :: Effects) a r.
(e2 <: es) =>
Int
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield (Int, a) e2
-> Eff es r
enumerateFrom Int
0 Yield a e1 -> Eff (e1 :& es) r
forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
s
enumerateFrom ::
(e2 <: es) =>
Int ->
(forall e1. Yield a e1 -> Eff (e1 :& es) r) ->
Yield (Int, a) e2 ->
Eff es r
enumerateFrom :: forall (e2 :: Effects) (es :: Effects) a r.
(e2 <: es) =>
Int
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield (Int, a) e2
-> Eff es r
enumerateFrom Int
n forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
ss Yield (Int, a) e2
st =
Int
-> (forall {e :: Effects}. Modify Int e -> Eff (e :& es) r)
-> Eff es r
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
evalState Int
n ((forall {e :: Effects}. Modify Int e -> Eff (e :& es) r)
-> Eff es r)
-> (forall {e :: Effects}. Modify Int e -> Eff (e :& es) r)
-> Eff es r
forall a b. (a -> b) -> a -> b
$ \Modify Int e
i -> (forall (e1 :: Effects).
Request a () e1 -> Eff (e1 :& (e :& es)) r)
-> (a -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r)
-> (Request a () e1 -> Eff (e1 :& es) r)
-> Request a () e1
-> Eff (e1 :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request a () e1 -> Eff (e1 :& es) r
forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
ss) ((a -> Eff (e :& es) ()) -> Eff (e :& es) r)
-> (a -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b. (a -> b) -> a -> b
$ \a
s -> do
Int
ii <- Modify Int e -> Eff (e :& es) Int
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify Int e
i
Yield (Int, a) e2 -> (Int, a) -> Eff (e :& es) ()
forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield Yield (Int, a) e2
st (Int
ii, a
s)
Modify Int e -> Int -> Eff (e :& es) ()
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> s -> Eff es ()
put Modify Int e
i (Int
ii Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
consumeEach ::
( forall e.
Consume b e ->
Eff (e :& es) r
) ->
Eff es b ->
Eff es r
consumeEach :: forall b (es :: Effects) r.
(forall (e :: Effects). Consume b e -> Eff (e :& es) r)
-> Eff es b -> Eff es r
consumeEach forall (e :: Effects). Consume b e -> Eff (e :& es) r
k Eff es b
e = (forall (e :: Effects). Consume b e -> Eff (e :& es) r)
-> (() -> Eff es b) -> Eff es r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach Consume b e1 -> Eff (e1 :& es) r
forall (e :: Effects). Consume b e -> Eff (e :& es) r
k (\() -> Eff es b
e)
await :: (e <: es) => Await a e -> Eff es a
await :: forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
Await a e -> Eff es a
await Await a e
r = Await a e -> () -> Eff es a
forall (e1 :: Effects) (es :: Effects) a b.
(e1 <: es) =>
Coroutine a b e1 -> a -> Eff es b
yieldCoroutine Await a e
r ()
type ReturnEarly = Throw
withEarlyReturn ::
(forall e. EarlyReturn r e -> Eff (e :& es) r) ->
Eff es r
withEarlyReturn :: forall r (es :: Effects).
(forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
withEarlyReturn = (r -> Eff es r)
-> (forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
forall exn (es :: Effects) a.
(exn -> Eff es a)
-> (forall (e :: Effects). Throw exn e -> Eff (e :& es) a)
-> Eff es a
handle r -> Eff es r
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
returnEarly ::
(e <: es) =>
ReturnEarly r e ->
r ->
Eff es a
returnEarly :: forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
returnEarly = Throw r e -> r -> Eff es a
forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
throw
evalState ::
s ->
(forall e. Modify s e -> Eff (e :& es) a) ->
Eff es a
evalState :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
evalState s
s forall (e :: Effects). Modify s e -> Eff (e :& es) a
f = ((a, s) -> a) -> Eff es (a, s) -> Eff es a
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s) -> a
forall a b. (a, b) -> a
fst (s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runState s
s Modify s e -> Eff (e :& es) a
forall (e :: Effects). Modify s e -> Eff (e :& es) a
f)
withState ::
s ->
(forall e. Modify s e -> Eff (e :& es) (s -> a)) ->
Eff es a
withState :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a))
-> Eff es a
withState s
s forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a)
f = do
(s -> a
g, s
s') <- s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a))
-> Eff es (s -> a, s)
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runState s
s Modify s e -> Eff (e :& es) (s -> a)
forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a)
f
a -> Eff es a
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (s -> a
g s
s')
data Compound e1 e2 ss where
Compound ::
Proxy# s1 ->
Proxy# s2 ->
e1 s1 ->
e2 s2 ->
Compound e1 e2 (s1 :& s2)
compound ::
h1 e1 ->
h2 e2 ->
Compound h1 h2 (e1 :& e2)
compound :: forall (h1 :: Effects -> *) (e1 :: Effects) (h2 :: Effects -> *)
(e2 :: Effects).
h1 e1 -> h2 e2 -> Compound h1 h2 (e1 :& e2)
compound = Proxy# e1
-> Proxy# e2 -> h1 e1 -> h2 e2 -> Compound h1 h2 (e1 :& e2)
forall (s1 :: Effects) (s2 :: Effects) (e1 :: Effects -> *)
(e2 :: Effects -> *).
Proxy# s1
-> Proxy# s2 -> e1 s1 -> e2 s2 -> Compound e1 e2 (s1 :& s2)
Compound Proxy# e1
forall {k} (a :: k). Proxy# a
proxy# Proxy# e2
forall {k} (a :: k). Proxy# a
proxy#
inComp :: forall a b c r. (a <: b) => (b <: c) => ((a <: c) => r) -> r
inComp :: forall (a :: Effects) (b :: Effects) (c :: Effects) r.
(a <: b, b <: c) =>
((a <: c) => r) -> r
inComp (a <: c) => r
k = case In a c -> Dict (a <: c)
forall (a :: Effects) (b :: Effects). In a b -> Dict (a <: b)
have (In a b -> In b c -> In a c
forall (a :: Effects) (b :: Effects) (c :: Effects).
In a b -> In b c -> In a c
cmp (forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has @a @b) (forall (a :: Effects) (b :: Effects). (a <: b) => In a b
has @b @c)) of Dict (a <: c)
Dict -> r
(a <: c) => r
k
withCompound ::
forall h1 h2 e es r.
(e <: es) =>
Compound h1 h2 e ->
(forall e1 e2. (e1 <: es, e2 <: es) => h1 e1 -> h2 e2 -> Eff es r) ->
Eff es r
withCompound :: forall (h1 :: Effects -> *) (h2 :: Effects -> *) (e :: Effects)
(es :: Effects) r.
(e <: es) =>
Compound h1 h2 e
-> (forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
h1 e1 -> h2 e2 -> Eff es r)
-> Eff es r
withCompound Compound h1 h2 e
c forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
h1 e1 -> h2 e2 -> Eff es r
f =
case Compound h1 h2 e
c of
Compound (Proxy# s1
_ :: Proxy# st) (Proxy# s2
_ :: Proxy# st') h1 s1
h h2 s2
i ->
forall (a :: Effects) (b :: Effects) (c :: Effects) r.
(a <: b, b <: c) =>
((a <: c) => r) -> r
inComp @st @e @es (forall (a :: Effects) (b :: Effects) (c :: Effects) r.
(a <: b, b <: c) =>
((a <: c) => r) -> r
inComp @st' @e @es (h1 s1 -> h2 s2 -> Eff es r
forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
h1 e1 -> h2 e2 -> Eff es r
f h1 s1
h h2 s2
i))
withC1 ::
forall e1 e2 ss es r.
(ss <: es) =>
Compound e1 e2 ss ->
(forall st. (st <: es) => e1 st -> Eff es r) ->
Eff es r
withC1 :: forall (e1 :: Effects -> *) (e2 :: Effects -> *) (ss :: Effects)
(es :: Effects) r.
(ss <: es) =>
Compound e1 e2 ss
-> (forall (st :: Effects). (st <: es) => e1 st -> Eff es r)
-> Eff es r
withC1 Compound e1 e2 ss
c forall (st :: Effects). (st <: es) => e1 st -> Eff es r
f = Compound e1 e2 ss
-> (forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
e1 e1 -> e2 e2 -> Eff es r)
-> Eff es r
forall (h1 :: Effects -> *) (h2 :: Effects -> *) (e :: Effects)
(es :: Effects) r.
(e <: es) =>
Compound h1 h2 e
-> (forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
h1 e1 -> h2 e2 -> Eff es r)
-> Eff es r
withCompound Compound e1 e2 ss
c (\e1 e1
h e2 e2
_ -> e1 e1 -> Eff es r
forall (st :: Effects). (st <: es) => e1 st -> Eff es r
f e1 e1
h)
withC2 ::
forall e1 e2 ss es r.
(ss <: es) =>
Compound e1 e2 ss ->
(forall st. (st <: es) => e2 st -> Eff es r) ->
Eff es r
withC2 :: forall (e1 :: Effects -> *) (e2 :: Effects -> *) (ss :: Effects)
(es :: Effects) r.
(ss <: es) =>
Compound e1 e2 ss
-> (forall (st :: Effects). (st <: es) => e2 st -> Eff es r)
-> Eff es r
withC2 Compound e1 e2 ss
c forall (st :: Effects). (st <: es) => e2 st -> Eff es r
f = Compound e1 e2 ss
-> (forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
e1 e1 -> e2 e2 -> Eff es r)
-> Eff es r
forall (h1 :: Effects -> *) (h2 :: Effects -> *) (e :: Effects)
(es :: Effects) r.
(e <: es) =>
Compound h1 h2 e
-> (forall (e1 :: Effects) (e2 :: Effects).
(e1 <: es, e2 <: es) =>
h1 e1 -> h2 e2 -> Eff es r)
-> Eff es r
withCompound Compound e1 e2 ss
c (\e1 e1
_ e2 e2
i -> e2 e2 -> Eff es r
forall (st :: Effects). (st <: es) => e2 st -> Eff es r
f e2 e2
i)
putC :: forall ss es e. (ss <: es) => Compound e (Modify Int) ss -> Int -> Eff es ()
putC :: forall (ss :: Effects) (es :: Effects) (e :: Effects -> *).
(ss <: es) =>
Compound e (Modify Int) ss -> Int -> Eff es ()
putC Compound e (Modify Int) ss
c Int
i = Compound e (Modify Int) ss
-> (forall (st :: Effects).
(st <: es) =>
Modify Int st -> Eff es ())
-> Eff es ()
forall (e1 :: Effects -> *) (e2 :: Effects -> *) (ss :: Effects)
(es :: Effects) r.
(ss <: es) =>
Compound e1 e2 ss
-> (forall (st :: Effects). (st <: es) => e2 st -> Eff es r)
-> Eff es r
withC2 Compound e (Modify Int) ss
c (\Modify Int st
h -> Modify Int st -> Int -> Eff es ()
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> s -> Eff es ()
put Modify Int st
h Int
i)
getC :: forall ss es e. (ss <: es) => Compound e (Modify Int) ss -> Eff es Int
getC :: forall (ss :: Effects) (es :: Effects) (e :: Effects -> *).
(ss <: es) =>
Compound e (Modify Int) ss -> Eff es Int
getC Compound e (Modify Int) ss
c = Compound e (Modify Int) ss
-> (forall (st :: Effects).
(st <: es) =>
Modify Int st -> Eff es Int)
-> Eff es Int
forall (e1 :: Effects -> *) (e2 :: Effects -> *) (ss :: Effects)
(es :: Effects) r.
(ss <: es) =>
Compound e1 e2 ss
-> (forall (st :: Effects). (st <: es) => e2 st -> Eff es r)
-> Eff es r
withC2 Compound e (Modify Int) ss
c (\Modify Int st
h -> Modify Int st -> Eff es Int
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify Int st
h)
runCompound ::
e1 s1 ->
e2 s2 ->
(forall es'. Compound e1 e2 es' -> Eff (es' :& es) r) ->
Eff (s1 :& (s2 :& es)) r
runCompound :: forall (e1 :: Effects -> *) (s1 :: Effects) (e2 :: Effects -> *)
(s2 :: Effects) (es :: Effects) r.
e1 s1
-> e2 s2
-> (forall (es' :: Effects).
Compound e1 e2 es' -> Eff (es' :& es) r)
-> Eff (s1 :& (s2 :& es)) r
runCompound e1 s1
e1 e2 s2
e2 forall (es' :: Effects). Compound e1 e2 es' -> Eff (es' :& es) r
k = Eff ((s1 :& s2) :& es) r -> Eff (s1 :& (s2 :& es)) r
forall (a :: Effects) (b :: Effects) (c :: Effects) r.
Eff ((a :& b) :& c) r -> Eff (a :& (b :& c)) r
assoc1Eff (Compound e1 e2 (s1 :& s2) -> Eff ((s1 :& s2) :& es) r
forall (es' :: Effects). Compound e1 e2 es' -> Eff (es' :& es) r
k (e1 s1 -> e2 s2 -> Compound e1 e2 (s1 :& s2)
forall (h1 :: Effects -> *) (e1 :: Effects) (h2 :: Effects -> *)
(e2 :: Effects).
h1 e1 -> h2 e2 -> Compound h1 h2 (e1 :& e2)
compound e1 s1
e1 e2 s2
e2))
yieldToList ::
(forall e1. Yield a e1 -> Eff (e1 :& es) r) ->
Eff es ([a], r)
yieldToList :: forall a (es :: Effects) r.
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
yieldToList forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
f = do
([a]
as, r
r) <- (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
forall a (es :: Effects) r.
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
yieldToReverseList Yield a e -> Eff (e :& es) r
forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
f
([a], r) -> Eff es ([a], r)
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
as, r
r)
yieldToPureList :: (forall e. Yield a e -> Eff e r) -> ([a], r)
yieldToPureList :: forall a r.
(forall (e :: Effects). Yield a e -> Eff e r) -> ([a], r)
yieldToPureList forall (e :: Effects). Yield a e -> Eff e r
f = (forall (es :: Effects). Eff es ([a], r)) -> ([a], r)
forall a. (forall (es :: Effects). Eff es a) -> a
runPureEff ((forall (es :: Effects). Eff es ([a], r)) -> ([a], r))
-> (forall (es :: Effects). Eff es ([a], r)) -> ([a], r)
forall a b. (a -> b) -> a -> b
$ (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
forall a (es :: Effects) r.
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
yieldToList ((forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r))
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
forall a b. (a -> b) -> a -> b
$ \Yield a e1
y -> Eff e1 r -> Eff (e1 :& es) r
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Eff e r -> Eff es r
useImpl (Yield a e1 -> Eff e1 r
forall (e :: Effects). Yield a e -> Eff e r
f Yield a e1
y)
withYieldToList ::
(forall e. Yield a e -> Eff (e :& es) ([a] -> r)) ->
Eff es r
withYieldToList :: forall a (es :: Effects) r.
(forall (e :: Effects). Yield a e -> Eff (e :& es) ([a] -> r))
-> Eff es r
withYieldToList forall (e :: Effects). Yield a e -> Eff (e :& es) ([a] -> r)
f = do
([a]
l, [a] -> r
g) <- (forall (e :: Effects). Yield a e -> Eff (e :& es) ([a] -> r))
-> Eff es ([a], [a] -> r)
forall a (es :: Effects) r.
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
yieldToList Yield a e1 -> Eff (e1 :& es) ([a] -> r)
forall (e :: Effects). Yield a e -> Eff (e :& es) ([a] -> r)
f
r -> Eff es r
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a] -> r
g [a]
l)
yieldToReverseList ::
(forall e. Yield a e -> Eff (e :& es) r) ->
Eff es ([a], r)
yieldToReverseList :: forall a (es :: Effects) r.
(forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Eff es ([a], r)
yieldToReverseList forall (e :: Effects). Yield a e -> Eff (e :& es) r
f = do
[a]
-> (forall {e :: Effects}. Modify [a] e -> Eff (e :& es) ([a], r))
-> Eff es ([a], r)
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
evalState [] ((forall {e :: Effects}. Modify [a] e -> Eff (e :& es) ([a], r))
-> Eff es ([a], r))
-> (forall {e :: Effects}. Modify [a] e -> Eff (e :& es) ([a], r))
-> Eff es ([a], r)
forall a b. (a -> b) -> a -> b
$ \(Modify [a] e
s :: Modify lo st) -> do
r
r <- (forall (e1 :: Effects).
Request a () e1 -> Eff (e1 :& (e :& es)) r)
-> (a -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r)
-> (Request a () e1 -> Eff (e1 :& es) r)
-> Request a () e1
-> Eff (e1 :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request a () e1 -> Eff (e1 :& es) r
forall (e :: Effects). Yield a e -> Eff (e :& es) r
f) ((a -> Eff (e :& es) ()) -> Eff (e :& es) r)
-> (a -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b. (a -> b) -> a -> b
$ \a
i ->
Modify [a] e -> ([a] -> [a]) -> Eff (e :& es) ()
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> (s -> s) -> Eff es ()
modify Modify [a] e
s (a
i :)
[a]
as <- Modify [a] e -> Eff (e :& es) [a]
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> Eff es s
get Modify [a] e
s
([a], r) -> Eff (e :& es) ([a], r)
forall a. a -> Eff (e :& es) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a]
as, r
r)
mapMaybe ::
(e2 <: es) =>
(a -> Maybe b) ->
(forall e1. Yield a e1 -> Eff (e1 :& es) r) ->
Yield b e2 ->
Eff es r
mapMaybe :: forall (e2 :: Effects) (es :: Effects) a b r.
(e2 <: es) =>
(a -> Maybe b)
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield b e2
-> Eff es r
mapMaybe a -> Maybe b
f forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
s Yield b e2
y = (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> (a -> Eff es ()) -> Eff es r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach Yield a e1 -> Eff (e1 :& es) r
forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r
s ((a -> Eff es ()) -> Eff es r) -> (a -> Eff es ()) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \a
a -> do
case a -> Maybe b
f a
a of
Maybe b
Nothing -> () -> Eff es ()
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just b
b_ -> Yield b e2 -> b -> Eff es ()
forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield Yield b e2
y b
b_
catMaybes ::
(e2 <: es) =>
(forall e1. Yield (Maybe a) e1 -> Eff (e1 :& es) r) ->
Yield a e2 ->
Eff es r
catMaybes :: forall (e2 :: Effects) (es :: Effects) a r.
(e2 <: es) =>
(forall (e1 :: Effects). Yield (Maybe a) e1 -> Eff (e1 :& es) r)
-> Yield a e2 -> Eff es r
catMaybes forall (e1 :: Effects). Yield (Maybe a) e1 -> Eff (e1 :& es) r
s Yield a e2
y = (Maybe a -> Maybe a)
-> (forall (e1 :: Effects). Yield (Maybe a) e1 -> Eff (e1 :& es) r)
-> Yield a e2
-> Eff es r
forall (e2 :: Effects) (es :: Effects) a b r.
(e2 <: es) =>
(a -> Maybe b)
-> (forall (e1 :: Effects). Yield a e1 -> Eff (e1 :& es) r)
-> Yield b e2
-> Eff es r
mapMaybe Maybe a -> Maybe a
forall a. a -> a
id Yield (Maybe a) e1 -> Eff (e1 :& es) r
forall (e1 :: Effects). Yield (Maybe a) e1 -> Eff (e1 :& es) r
s Yield a e2
y
cycleToStream ::
(Foldable f, e1 <: es) =>
f a ->
Yield a e1 ->
Eff es ()
cycleToStream :: forall (t :: * -> *) (e1 :: Effects) (es :: Effects) a.
(Foldable t, e1 <: es) =>
t a -> Yield a e1 -> Eff es ()
cycleToStream f a
f Yield a e1
y = do
Eff es () -> Eff es ()
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (f a -> Yield a e1 -> Eff es ()
forall (t :: * -> *) (e1 :: Effects) (es :: Effects) a.
(Foldable t, e1 <: es) =>
t a -> Yield a e1 -> Eff es ()
inFoldable f a
f Yield a e1
y)
takeConsume ::
(e1 <: es, e2 <: es) =>
Int ->
Consume a e1 ->
Stream a e2 ->
Eff es ()
takeConsume :: forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) a.
(e1 <: es, e2 <: es) =>
Int -> Consume a e1 -> Stream a e2 -> Eff es ()
takeConsume Int
count Consume a e1
source Stream a e2
sink = Int -> Eff es ()
loop Int
count
where
loop :: Int -> Eff es ()
loop Int
c | Int
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = () -> Eff es ()
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loop Int
c = do
Consume a e1 -> Eff es a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
Await a e -> Eff es a
await Consume a e1
source Eff es a -> (a -> Eff es ()) -> Eff es ()
forall a b. Eff es a -> (a -> Eff es b) -> Eff es b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Stream a e2 -> a -> Eff es ()
forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield Stream a e2
sink
Int -> Eff es ()
loop (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
type JumpTo = ReturnEarly ()
withJump ::
(forall e. Jump e -> Eff (e :& es) ()) ->
Eff es ()
withJump :: forall (es :: Effects).
(forall (e :: Effects). Jump e -> Eff (e :& es) ()) -> Eff es ()
withJump = (forall (e :: Effects). EarlyReturn () e -> Eff (e :& es) ())
-> Eff es ()
forall r (es :: Effects).
(forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
withEarlyReturn
jumpTo ::
(e <: es) =>
JumpTo e ->
Eff es a
jumpTo :: forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
JumpTo e -> Eff es a
jumpTo JumpTo e
tag = JumpTo e -> () -> Eff es a
forall (e :: Effects) (es :: Effects) ex a.
(e <: es) =>
Throw ex e -> ex -> Eff es a
throw JumpTo e
tag ()
unwrap :: (e <: es) => JumpTo e -> Maybe a -> Eff es a
unwrap :: forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
JumpTo e -> Maybe a -> Eff es a
unwrap JumpTo e
j = \case
Maybe a
Nothing -> JumpTo e -> Eff es a
forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
JumpTo e -> Eff es a
jumpTo JumpTo e
j
Just a
a -> a -> Eff es a
forall a. a -> Eff es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
data IOE (e :: Effects) = MkIOE
deriving (HandleD IOE
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (IOE e) (IOE es)) =>
HandleD IOE -> Handle IOE
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (IOE e) (IOE es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: HandleD IOE
handleImpl :: HandleD IOE
Handle) via OneWayCoercibleHandle IOE
type role IOE nominal
instance (e <: es) => OneWayCoercible (IOE e) (IOE es) where
oneWayCoercibleImpl :: OneWayCoercibleD (IOE e) (IOE es)
oneWayCoercibleImpl = OneWayCoercibleD (IOE e) (IOE es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
effIO ::
(e <: es) =>
IOE e ->
IO a ->
Eff es a
effIO :: forall (e :: Effects) (es :: Effects) a.
(e <: es) =>
IOE e -> IO a -> Eff es a
effIO IOE e
MkIOE = (Env -> IO a) -> Eff es a
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO a) -> Eff es a)
-> (IO a -> Env -> IO a) -> IO a -> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> Env -> IO a
forall a b. a -> b -> a
const
runEff ::
(forall e. IOE e -> Eff e a) ->
IO a
runEff :: forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff forall (e :: Effects). IOE e -> Eff e a
eff = (forall (e :: Effects). IOE e -> Eff e a) -> IO a
forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff_ IOE e -> Eff e a
forall (e :: Effects). IOE e -> Eff e a
eff
runEff_ ::
(forall e. IOE e -> Eff e a) ->
IO a
runEff_ :: forall a. (forall (e :: Effects). IOE e -> Eff e a) -> IO a
runEff_ forall (e :: Effects). IOE e -> Eff e a
eff = do
Env
emptyEnv <- Vault -> IO Env
forall a. a -> IO (IORef a)
newIORef Vault
Vault.empty
Eff Any a -> Env -> IO a
forall (es :: Effects) a. Eff es a -> Env -> IO a
unsafeUnEff (IOE Any -> Eff Any a
forall (e :: Effects). IOE e -> Eff e a
eff IOE Any
forall (e :: Effects). IOE e
MkIOE) Env
emptyEnv
unsafeProvideIO ::
(forall e. IOE e -> Eff (e :& es) a) ->
Eff es a
unsafeProvideIO :: forall (es :: Effects) a.
(forall (e :: Effects). IOE e -> Eff (e :& es) a) -> Eff es a
unsafeProvideIO forall (e :: Effects). IOE e -> Eff (e :& es) a
eff = (IOE es -> Eff (es :& es) a) -> IOE es -> Eff es a
forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn IOE es -> Eff (es :& es) a
forall (e :: Effects). IOE e -> Eff (e :& es) a
eff IOE es
forall (e :: Effects). IOE e
MkIOE
newtype Tell w e = Tell (Yield w e)
deriving (HandleD (Tell w)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Tell w e) (Tell w es)) =>
HandleD (Tell w) -> Handle (Tell w)
forall w. HandleD (Tell w)
forall w (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Tell w e) (Tell w es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Tell w e) (Tell w es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall w. HandleD (Tell w)
handleImpl :: HandleD (Tell w)
Handle) via OneWayCoercibleHandle (Tell w)
instance (e <: es) => OneWayCoercible (Tell w e) (Tell w es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Tell w e) (Tell w es)
oneWayCoercibleImpl = OneWayCoercibleD (Tell w e) (Tell w es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
runWriter ::
(Monoid w) =>
(forall e. Writer w e -> Eff (e :& es) r) ->
Eff es (r, w)
runWriter :: forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
runWriter forall (e :: Effects). Writer w e -> Eff (e :& es) r
f = w
-> (forall {e :: Effects}. Modify w e -> Eff (e :& es) r)
-> Eff es (r, w)
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runState w
forall a. Monoid a => a
mempty ((forall {e :: Effects}. Modify w e -> Eff (e :& es) r)
-> Eff es (r, w))
-> (forall {e :: Effects}. Modify w e -> Eff (e :& es) r)
-> Eff es (r, w)
forall a b. (a -> b) -> a -> b
$ \Modify w e
st -> do
(forall (e1 :: Effects).
Request w () e1 -> Eff (e1 :& (e :& es)) r)
-> (w -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b (es :: Effects) r.
(forall (e1 :: Effects). Request a b e1 -> Eff (e1 :& es) r)
-> (a -> Eff es b) -> Eff es r
forEach (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r
forall (e :: Effects) (es :: Effects) (e1 :: Effects) r.
(e <: es) =>
Eff (e1 :& e) r -> Eff (e1 :& es) r
useImplUnder (Eff (e1 :& es) r -> Eff (e1 :& (e :& es)) r)
-> (Request w () e1 -> Eff (e1 :& es) r)
-> Request w () e1
-> Eff (e1 :& (e :& es)) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Writer w e1 -> Eff (e1 :& es) r
forall (e :: Effects). Writer w e -> Eff (e :& es) r
f (Writer w e1 -> Eff (e1 :& es) r)
-> (Request w () e1 -> Writer w e1)
-> Request w () e1
-> Eff (e1 :& es) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request w () e1 -> Writer w e1
forall w (e :: Effects). Yield w e -> Tell w e
Tell) ((w -> Eff (e :& es) ()) -> Eff (e :& es) r)
-> (w -> Eff (e :& es) ()) -> Eff (e :& es) r
forall a b. (a -> b) -> a -> b
$ \w
ww -> do
Modify w e -> (w -> w) -> Eff (e :& es) ()
forall (e :: Effects) (es :: Effects) s.
(e <: es) =>
Modify s e -> (s -> s) -> Eff es ()
modify Modify w e
st (w -> w -> w
forall a. Semigroup a => a -> a -> a
<> w
ww)
execWriter ::
(Monoid w) =>
(forall e. Writer w e -> Eff (e :& es) r) ->
Eff es w
execWriter :: forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r) -> Eff es w
execWriter forall (e :: Effects). Writer w e -> Eff (e :& es) r
f = ((r, w) -> w) -> Eff es (r, w) -> Eff es w
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, w) -> w
forall a b. (a, b) -> b
snd ((forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
runWriter Tell w e -> Eff ('Union e es) r
forall (e :: Effects). Writer w e -> Eff (e :& es) r
f)
tell ::
(e <: es) =>
Tell w e ->
w ->
Eff es ()
tell :: forall (e :: Effects) (es :: Effects) w.
(e <: es) =>
Tell w e -> w -> Eff es ()
tell (Tell Yield w e
y) = Yield w e -> w -> Eff es ()
forall (e1 :: Effects) (es :: Effects) a.
(e1 <: es) =>
Yield a e1 -> a -> Eff es ()
yield Yield w e
y
type Ask :: Type -> Effects -> Type
newtype Ask r e = MkReader (Vault.Key r)
deriving (HandleD (Ask r)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Ask r e) (Ask r es)) =>
HandleD (Ask r) -> Handle (Ask r)
forall r. HandleD (Ask r)
forall r (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Ask r e) (Ask r es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (Ask r e) (Ask r es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall r. HandleD (Ask r)
handleImpl :: HandleD (Ask r)
Handle) via OneWayCoercibleHandle (Ask r)
instance (e <: es) => OneWayCoercible (Ask r e) (Ask r es) where
oneWayCoercibleImpl :: OneWayCoercibleD (Ask r e) (Ask r es)
oneWayCoercibleImpl = OneWayCoercibleD (Ask r e) (Ask r es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
type role Ask representational nominal
runReader ::
r ->
(forall e. Reader r e -> Eff (e :& es) a) ->
Eff es a
runReader :: forall r (es :: Effects) a.
r
-> (forall (e :: Effects). Reader r e -> Eff (e :& es) a)
-> Eff es a
runReader r
r forall (e :: Effects). Reader r e -> Eff (e :& es) a
f = do
Eff es (Key r)
-> (Key r -> Eff es ()) -> (Key r -> Eff es a) -> Eff es a
forall (es :: Effects) a b.
Eff es a -> (a -> Eff es ()) -> (a -> Eff es b) -> Eff es b
bracket
( (Env -> IO (Key r)) -> Eff es (Key r)
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO (Key r)) -> Eff es (Key r))
-> (Env -> IO (Key r)) -> Eff es (Key r)
forall a b. (a -> b) -> a -> b
$ \Env
vault -> do
Key r
k <- IO (Key r)
forall a. IO (Key a)
Vault.newKey
Env -> (Vault -> Vault) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' Env
vault (\Vault
v -> Key r -> r -> Vault -> Vault
forall a. Key a -> a -> Vault -> Vault
Vault.insert Key r
k r
r Vault
v)
Key r -> IO (Key r)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Key r
k
)
(\Key r
k -> (Env -> IO ()) -> Eff es ()
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO ()) -> Eff es ()) -> (Env -> IO ()) -> Eff es ()
forall a b. (a -> b) -> a -> b
$ \Env
vault -> Env -> (Vault -> Vault) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' Env
vault (Key r -> Vault -> Vault
forall a. Key a -> Vault -> Vault
Vault.delete Key r
k))
(\Key r
k -> Eff (es :& es) a -> Eff es a
forall (a :: Effects) r. Eff (a :& a) r -> Eff a r
makeOp (Reader r es -> Eff (es :& es) a
forall (e :: Effects). Reader r e -> Eff (e :& es) a
f (Key r -> Reader r es
forall r (e :: Effects). Key r -> Ask r e
MkReader Key r
k)))
ask ::
(e <: es) =>
Ask r e ->
Eff es r
ask :: forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Ask r e -> Eff es r
ask (MkReader Key r
k) = (Env -> IO r) -> Eff es r
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO r) -> Eff es r) -> (Env -> IO r) -> Eff es r
forall a b. (a -> b) -> a -> b
$ \Env
vault -> do
Vault
v <- Env -> IO Vault
forall a. IORef a -> IO a
readIORef Env
vault
case Key r -> Vault -> Maybe r
forall a. Key a -> Vault -> Maybe a
Vault.lookup Key r
k Vault
v of
Maybe r
Nothing -> String -> IO r
forall a. HasCallStack => String -> a
error String
msg
Just r
ref -> r -> IO r
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r
ref
where
msg :: String
msg =
[String] -> String
unlines
[ String
"ask called on out of scope reference",
[String] -> String
unwords
[ String
"If you haven't subverted Bluefin's type system",
String
"then this is a Bluefin bug.",
String
"Please report it at",
String
"https://github.com/tomjaguarpaw/bluefin/issues/new"
]
]
asks ::
(e <: es) =>
Ask r e ->
(r -> a) ->
Eff es a
asks :: forall (e :: Effects) (es :: Effects) r a.
(e <: es) =>
Ask r e -> (r -> a) -> Eff es a
asks Ask r e
r r -> a
f = (r -> a) -> Eff es r -> Eff es a
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap r -> a
f (Ask r e -> Eff es r
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Ask r e -> Eff es r
ask Ask r e
r)
local ::
(e1 <: es) =>
Ask r e1 ->
(r -> r) ->
Eff es a ->
Eff es a
local :: forall (e1 :: Effects) (es :: Effects) r a.
(e1 <: es) =>
Ask r e1 -> (r -> r) -> Eff es a -> Eff es a
local (MkReader Key r
key) r -> r
f Eff es a
k = (Env -> IO a) -> Eff es a
forall (es :: Effects) a. (Env -> IO a) -> Eff es a
UnsafeMkEff ((Env -> IO a) -> Eff es a) -> (Env -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \env :: Env
env@Env
vault -> do
Vault
orig <- Env -> IO Vault
forall a. IORef a -> IO a
readIORef Env
vault
IO () -> (() -> IO ()) -> (() -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
Control.Exception.bracket
(Env -> Vault -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef Env
vault ((r -> r) -> Key r -> Vault -> Vault
forall a. (a -> a) -> Key a -> Vault -> Vault
Vault.adjust r -> r
f Key r
key Vault
orig))
(\() -> Env -> Vault -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef Env
vault Vault
orig)
(\() -> case Eff es a
k of UnsafeMkEff Env -> IO a
m -> Env -> IO a
m Env
env)
newtype AskCapability h e = UnsafeMkHandleReader (Ask (h e) e)
deriving (HandleD (AskCapability h)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (AskCapability h e) (AskCapability h es)) =>
HandleD (AskCapability h) -> Handle (AskCapability h)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (AskCapability h e) (AskCapability h es)
forall (h :: Effects -> *). HandleD (AskCapability h)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (AskCapability h e) (AskCapability h es)
$chandleImpl :: forall (h :: Effects -> *). HandleD (AskCapability h)
handleImpl :: HandleD (AskCapability h)
Handle) via OneWayCoercibleHandle (AskCapability h)
mapHandleReader ::
forall h e es.
(Handle h, e <: es) =>
HandleReader h e ->
HandleReader h es
mapHandleReader :: forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
HandleReader h e -> HandleReader h es
mapHandleReader = case Coercion (h e) (h es)
coerceH of Coercion (h e) (h es)
Coercion -> HandleReader h e -> HandleReader h es
forall a b. Coercible a b => a -> b
coerce
where
oneWayCoerceH :: OneWayCoercion (h e) (h es)
oneWayCoerceH :: OneWayCoercion (h e) (h es)
oneWayCoerceH = OneWayCoercion (h e) (h es)
forall {k} (a :: k) (b :: k).
OneWayCoercible a b =>
OneWayCoercion a b
oneWayCoercion
coerceH :: Coercion (h e) (h es)
coerceH :: Coercion (h e) (h es)
coerceH = OneWayCoercion (h e) (h es) -> Coercion (h e) (h es)
forall {k} (a :: k) (b :: k). OneWayCoercion a b -> Coercion a b
unsafeCoercionOfOneWayCoercion OneWayCoercion (h e) (h es)
oneWayCoerceH
localHandle ::
(e <: es, Handle h) =>
HandleReader h e ->
(h es -> h es) ->
Eff es r ->
Eff es r
localHandle :: forall (e :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e <: es, Handle h) =>
HandleReader h e -> (h es -> h es) -> Eff es r -> Eff es r
localHandle HandleReader h e
hh h es -> h es
f Eff es r
k = do
let UnsafeMkHandleReader Ask (h es) es
st = HandleReader h e -> AskCapability h es
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle HandleReader h e
hh
Ask (h es) es -> (h es -> h es) -> Eff es r -> Eff es r
forall (e1 :: Effects) (es :: Effects) r a.
(e1 <: es) =>
Ask r e1 -> (r -> r) -> Eff es a -> Eff es a
local Ask (h es) es
st h es -> h es
f Eff es r
k
askHandle ::
(e <: es, Handle h) =>
HandleReader h e ->
Eff es (h es)
askHandle :: forall (e :: Effects) (es :: Effects) (h :: Effects -> *).
(e <: es, Handle h) =>
HandleReader h e -> Eff es (h es)
askHandle HandleReader h e
hh = let UnsafeMkHandleReader Ask (h es) es
st = HandleReader h e -> AskCapability h es
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle HandleReader h e
hh in Ask (h es) es -> Eff es (h es)
forall (e :: Effects) (es :: Effects) r.
(e <: es) =>
Ask r e -> Eff es r
ask Ask (h es) es
st
asksHandle ::
(e1 <: es, Handle h) =>
HandleReader h e1 ->
(forall e. h e -> Eff (e :& es) r) ->
Eff es r
asksHandle :: forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
HandleReader h e1
-> (forall (e :: Effects). h e -> Eff (e :& es) r) -> Eff es r
asksHandle HandleReader h e1
hh forall (e :: Effects). h e -> Eff (e :& es) r
k = do
h es
h <- HandleReader h e1 -> Eff es (h es)
forall (e :: Effects) (es :: Effects) (h :: Effects -> *).
(e <: es, Handle h) =>
HandleReader h e -> Eff es (h es)
askHandle HandleReader h e1
hh
Eff (es :& es) r -> Eff es r
forall (a :: Effects) r. Eff (a :& a) r -> Eff a r
makeOp (h es -> Eff (es :& es) r
forall (e :: Effects). h e -> Eff (e :& es) r
k h es
h)
runHandleReader ::
(e1 <: es, Handle h) =>
h e1 ->
(forall e. HandleReader h e -> Eff (e :& es) r) ->
Eff es r
runHandleReader :: forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
h e1
-> (forall (e :: Effects). HandleReader h e -> Eff (e :& es) r)
-> Eff es r
runHandleReader h e1
h forall (e :: Effects). HandleReader h e -> Eff (e :& es) r
k = do
h es
-> (forall {e :: Effects}. Reader (h es) e -> Eff (e :& es) r)
-> Eff es r
forall r (es :: Effects) a.
r
-> (forall (e :: Effects). Reader r e -> Eff (e :& es) a)
-> Eff es a
runReader (h e1 -> h es
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle h e1
h) ((forall {e :: Effects}. Reader (h es) e -> Eff (e :& es) r)
-> Eff es r)
-> (forall {e :: Effects}. Reader (h es) e -> Eff (e :& es) r)
-> Eff es r
forall a b. (a -> b) -> a -> b
$ \(Reader (h es) e
st :: Ask (h es) e) -> do
let oneWayCoerceH :: OneWayCoercion (h es) (h (e :& es))
oneWayCoerceH :: OneWayCoercion (h es) (h (e :& es))
oneWayCoerceH = OneWayCoercion (h es) (h (e :& es))
forall {k} (a :: k) (b :: k).
OneWayCoercible a b =>
OneWayCoercion a b
oneWayCoercion
let coerceH :: Coercion (h es) (h (e :& es))
coerceH :: Coercion (h es) (h (e :& es))
coerceH = OneWayCoercion (h es) (h (e :& es))
-> Coercion (h es) (h (e :& es))
forall {k} (a :: k) (b :: k). OneWayCoercion a b -> Coercion a b
unsafeCoercionOfOneWayCoercion OneWayCoercion (h es) (h (e :& es))
oneWayCoerceH
let mapS :: Ask (h es) e' -> Ask (h (e :& es)) e'
mapS :: forall (e' :: Effects). Ask (h es) e' -> Ask (h (e :& es)) e'
mapS = case Coercion (h es) (h (e :& es))
coerceH of Coercion (h es) (h (e :& es))
Coercion -> Ask (h es) e' -> Ask (h (e :& es)) e'
forall a b. Coercible a b => a -> b
coerce
let h' :: HandleReader h (e :& es)
h' :: HandleReader h (e :& es)
h' = case Coercion (h es) (h (e :& es))
coerceH of
Coercion (h es) (h (e :& es))
Coercion ->
Ask (h (e :& es)) (e :& es) -> HandleReader h (e :& es)
forall (h :: Effects -> *) (e :: Effects).
Ask (h e) e -> AskCapability h e
UnsafeMkHandleReader (Ask (h es) (e :& es) -> Ask (h (e :& es)) (e :& es)
forall (e' :: Effects). Ask (h es) e' -> Ask (h (e :& es)) e'
mapS (Reader (h es) e -> Ask (h es) (e :& es)
forall (h :: Effects -> *) (e :: Effects) (es :: Effects).
(Handle h, e <: es) =>
h e -> h es
mapHandle Reader (h es) e
st))
(HandleReader h (e :& es) -> Eff ((e :& es) :& es) r)
-> HandleReader h (e :& es) -> Eff (e :& es) r
forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn HandleReader h (e :& es) -> Eff ((e :& es) :& es) r
forall (e :: Effects). HandleReader h e -> Eff (e :& es) r
k HandleReader h (e :& es)
h'
instance (e <: es) => OneWayCoercible (AskCapability h e) (AskCapability h es) where
oneWayCoercibleImpl :: OneWayCoercibleD (AskCapability h e) (AskCapability h es)
oneWayCoercibleImpl = OneWayCoercibleD (AskCapability h e) (AskCapability h es)
forall {k} (a :: k) (b :: k). OneWayCoercibleD a b
unsafeOneWayCoercible
newtype ConstEffect r (e :: Effects) = MkConstEffect r
deriving (HandleD (ConstEffect r)
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ConstEffect r e) (ConstEffect r es)) =>
HandleD (ConstEffect r) -> Handle (ConstEffect r)
forall r. HandleD (ConstEffect r)
forall r (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ConstEffect r e) (ConstEffect r es)
forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (ConstEffect r e) (ConstEffect r es)
forall (h :: Effects -> *).
(forall (e :: Effects) (es :: Effects).
(e <: es) =>
OneWayCoercible (h e) (h es)) =>
HandleD h -> Handle h
$chandleImpl :: forall r. HandleD (ConstEffect r)
handleImpl :: HandleD (ConstEffect r)
Handle) via OneWayCoercibleHandle (ConstEffect r)
instance (e <: es) => OneWayCoercible (ConstEffect r e) (ConstEffect r es) where
oneWayCoercibleImpl :: OneWayCoercibleD (ConstEffect r e) (ConstEffect r es)
oneWayCoercibleImpl = OneWayCoercibleD (ConstEffect r e) (ConstEffect r es)
forall {k} (a :: k) (b :: k). Coercible a b => OneWayCoercibleD a b
oneWayCoercible
runConstEffect ::
r ->
(forall e. ConstEffect r e -> Eff (e :& es) a) ->
Eff es a
runConstEffect :: forall r (es :: Effects) a.
r
-> (forall (e :: Effects). ConstEffect r e -> Eff (e :& es) a)
-> Eff es a
runConstEffect r
r forall (e :: Effects). ConstEffect r e -> Eff (e :& es) a
k = (ConstEffect r es -> Eff (es :& es) a)
-> ConstEffect r es -> Eff es a
forall (e :: Effects) (es :: Effects) t r.
(e <: es) =>
(t -> Eff (es :& e) r) -> t -> Eff es r
useImplIn ConstEffect r es -> Eff (es :& es) a
forall (e :: Effects). ConstEffect r e -> Eff (e :& es) a
k (r -> ConstEffect r es
forall r (e :: Effects). r -> ConstEffect r e
MkConstEffect r
r)
type Reader = Ask
type HandleReader = AskCapability
type Consume a = Await a
type Jump = JumpTo
type Coroutine = Request
type EarlyReturn r = ReturnEarly r
type State = Modify
type Writer = Tell
type Exception = Throw
type Stream a = Yield a
runAsk ::
r ->
(forall e. Ask r e -> Eff (e :& es) a) ->
Eff es a
runAsk :: forall r (es :: Effects) a.
r
-> (forall (e :: Effects). Reader r e -> Eff (e :& es) a)
-> Eff es a
runAsk = r
-> (forall (e :: Effects). Reader r e -> Eff (e :& es) a)
-> Eff es a
forall r (es :: Effects) a.
r
-> (forall (e :: Effects). Reader r e -> Eff (e :& es) a)
-> Eff es a
runReader
connectRequests ::
forall es a b r.
(forall e. Request a b e -> Eff (e :& es) r) ->
(forall e. a -> Request b a e -> Eff (e :& es) r) ->
Eff es r
connectRequests :: forall (es :: Effects) a b r.
(forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r)
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r)
-> Eff es r
connectRequests = (forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r)
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r)
-> Eff es r
forall (es :: Effects) a b r.
(forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r)
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r)
-> Eff es r
connectCoroutines
request ::
(e1 <: es) =>
Request a b e1 ->
a ->
Eff es b
request :: forall (e1 :: Effects) (es :: Effects) a b.
(e1 <: es) =>
Coroutine a b e1 -> a -> Eff es b
request = Coroutine a b e1 -> a -> Eff es b
forall (e1 :: Effects) (es :: Effects) a b.
(e1 <: es) =>
Coroutine a b e1 -> a -> Eff es b
yieldCoroutine
awaitYield ::
(forall e. Await a e -> Eff (e :& es) r) ->
(forall e. Yield a e -> Eff (e :& es) r) ->
Eff es r
awaitYield :: forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
awaitYield = (forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
forall a (es :: Effects) r.
(forall (e :: Effects). Consume a e -> Eff (e :& es) r)
-> (forall (e :: Effects). Stream a e -> Eff (e :& es) r)
-> Eff es r
consumeStream
eachAwait ::
(forall e. Await b e -> Eff (e :& es) r) ->
Eff es b ->
Eff es r
eachAwait :: forall b (es :: Effects) r.
(forall (e :: Effects). Consume b e -> Eff (e :& es) r)
-> Eff es b -> Eff es r
eachAwait = (forall (e :: Effects). Consume b e -> Eff (e :& es) r)
-> Eff es b -> Eff es r
forall b (es :: Effects) r.
(forall (e :: Effects). Consume b e -> Eff (e :& es) r)
-> Eff es b -> Eff es r
consumeEach
takeAwait ::
(e1 <: es, e2 <: es) =>
Int ->
Await a e1 ->
Yield a e2 ->
Eff es ()
takeAwait :: forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) a.
(e1 <: es, e2 <: es) =>
Int -> Consume a e1 -> Stream a e2 -> Eff es ()
takeAwait = Int -> Consume a e1 -> Stream a e2 -> Eff es ()
forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) a.
(e1 <: es, e2 <: es) =>
Int -> Consume a e1 -> Stream a e2 -> Eff es ()
takeConsume
ignoreYield ::
(forall e1. Yield a e1 -> Eff (e1 :& es) r) ->
Eff es r
ignoreYield :: forall a (es :: Effects) r.
(forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r)
-> Eff es r
ignoreYield = (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r)
-> Eff es r
forall a (es :: Effects) r.
(forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r)
-> Eff es r
ignoreStream
cycleToYield ::
(Foldable f, e1 <: es) =>
f a ->
Yield a e1 ->
Eff es ()
cycleToYield :: forall (t :: * -> *) (e1 :: Effects) (es :: Effects) a.
(Foldable t, e1 <: es) =>
t a -> Yield a e1 -> Eff es ()
cycleToYield = f a -> Yield a e1 -> Eff es ()
forall (t :: * -> *) (e1 :: Effects) (es :: Effects) a.
(Foldable t, e1 <: es) =>
t a -> Yield a e1 -> Eff es ()
cycleToStream
withReturnEarly ::
(forall e. ReturnEarly r e -> Eff (e :& es) r) ->
Eff es r
withReturnEarly :: forall r (es :: Effects).
(forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
withReturnEarly = (forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
forall r (es :: Effects).
(forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
withEarlyReturn
evalModify ::
s ->
(forall e. Modify s e -> Eff (e :& es) a) ->
Eff es a
evalModify :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
evalModify = s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es a
evalState
withModify ::
s ->
(forall e. Modify s e -> Eff (e :& es) (s -> a)) ->
Eff es a
withModify :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a))
-> Eff es a
withModify = s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a))
-> Eff es a
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) (s -> a))
-> Eff es a
withState
runModify ::
s ->
(forall e. Modify s e -> Eff (e :& es) a) ->
Eff es (a, s)
runModify :: forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runModify = s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
forall s (es :: Effects) a.
s
-> (forall (e :: Effects). Modify s e -> Eff (e :& es) a)
-> Eff es (a, s)
runState
runTell ::
(Monoid w) =>
(forall e. Tell w e -> Eff (e :& es) r) ->
Eff es (r, w)
runTell :: forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
runTell = (forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r)
-> Eff es (r, w)
runWriter
execTell ::
(Monoid w) =>
(forall e. Tell w e -> Eff (e :& es) r) ->
Eff es w
execTell :: forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r) -> Eff es w
execTell = (forall (e :: Effects). Writer w e -> Eff (e :& es) r) -> Eff es w
forall w (es :: Effects) r.
Monoid w =>
(forall (e :: Effects). Writer w e -> Eff (e :& es) r) -> Eff es w
execWriter
runAskCapability ::
(e1 <: es, Handle h) =>
h e1 ->
(forall e. AskCapability h e -> Eff (e :& es) r) ->
Eff es r
runAskCapability :: forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
h e1
-> (forall (e :: Effects). HandleReader h e -> Eff (e :& es) r)
-> Eff es r
runAskCapability = h e1
-> (forall (e :: Effects). HandleReader h e -> Eff (e :& es) r)
-> Eff es r
forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
h e1
-> (forall (e :: Effects). HandleReader h e -> Eff (e :& es) r)
-> Eff es r
runHandleReader
askCapability ::
(e <: es, Handle h) =>
AskCapability h e ->
Eff es (h es)
askCapability :: forall (e :: Effects) (es :: Effects) (h :: Effects -> *).
(e <: es, Handle h) =>
HandleReader h e -> Eff es (h es)
askCapability = HandleReader h e -> Eff es (h es)
forall (e :: Effects) (es :: Effects) (h :: Effects -> *).
(e <: es, Handle h) =>
HandleReader h e -> Eff es (h es)
askHandle
asksCapability ::
(e1 <: es, Handle h) =>
AskCapability h e1 ->
(forall e. h e -> Eff (e :& es) r) ->
Eff es r
asksCapability :: forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
HandleReader h e1
-> (forall (e :: Effects). h e -> Eff (e :& es) r) -> Eff es r
asksCapability = HandleReader h e1
-> (forall (e :: Effects). h e -> Eff (e :& es) r) -> Eff es r
forall (e1 :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e1 <: es, Handle h) =>
HandleReader h e1
-> (forall (e :: Effects). h e -> Eff (e :& es) r) -> Eff es r
asksHandle
localCapability ::
(e <: es, Handle h) =>
AskCapability h e ->
(h es -> h es) ->
Eff es r ->
Eff es r
localCapability :: forall (e :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e <: es, Handle h) =>
HandleReader h e -> (h es -> h es) -> Eff es r -> Eff es r
localCapability = HandleReader h e -> (h es -> h es) -> Eff es r -> Eff es r
forall (e :: Effects) (es :: Effects) (h :: Effects -> *) r.
(e <: es, Handle h) =>
HandleReader h e -> (h es -> h es) -> Eff es r -> Eff es r
localHandle
withJumpTo ::
(forall e. JumpTo e -> Eff (e :& es) ()) ->
Eff es ()
withJumpTo :: forall (es :: Effects).
(forall (e :: Effects). Jump e -> Eff (e :& es) ()) -> Eff es ()
withJumpTo = (forall (e :: Effects). EarlyReturn () e -> Eff (e :& es) ())
-> Eff es ()
forall r (es :: Effects).
(forall (e :: Effects). EarlyReturn r e -> Eff (e :& es) r)
-> Eff es r
withEarlyReturn