{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_HADDOCK not-home #-}
module Avail.Internal where
import Control.Monad.Fix (MonadFix)
import Control.Monad.Zip (MonadZip)
import Data.Kind (Constraint, Type)
import Data.Proxy (Proxy (Proxy))
import Unsafe.Coerce (unsafeCoerce)
#ifdef AVAIL_semigroupoids
import Data.Functor.Apply (Apply)
import Data.Functor.Bind (Bind (join, (>>-)))
#endif
newtype M m a = UnsafeLift (m a)
deriving newtype (a -> M m b -> M m a
(a -> b) -> M m a -> M m b
(forall a b. (a -> b) -> M m a -> M m b)
-> (forall a b. a -> M m b -> M m a) -> Functor (M m)
forall a b. a -> M m b -> M m a
forall a b. (a -> b) -> M m a -> M m b
forall (m :: * -> *) a b. Functor m => a -> M m b -> M m a
forall (m :: * -> *) a b. Functor m => (a -> b) -> M m a -> M m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> M m b -> M m a
$c<$ :: forall (m :: * -> *) a b. Functor m => a -> M m b -> M m a
fmap :: (a -> b) -> M m a -> M m b
$cfmap :: forall (m :: * -> *) a b. Functor m => (a -> b) -> M m a -> M m b
Functor, Functor (M m)
a -> M m a
Functor (M m)
-> (forall a. a -> M m a)
-> (forall a b. M m (a -> b) -> M m a -> M m b)
-> (forall a b c. (a -> b -> c) -> M m a -> M m b -> M m c)
-> (forall a b. M m a -> M m b -> M m b)
-> (forall a b. M m a -> M m b -> M m a)
-> Applicative (M m)
M m a -> M m b -> M m b
M m a -> M m b -> M m a
M m (a -> b) -> M m a -> M m b
(a -> b -> c) -> M m a -> M m b -> M m c
forall a. a -> M m a
forall a b. M m a -> M m b -> M m a
forall a b. M m a -> M m b -> M m b
forall a b. M m (a -> b) -> M m a -> M m b
forall a b c. (a -> b -> c) -> M m a -> M m b -> M m 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
forall (m :: * -> *). Applicative m => Functor (M m)
forall (m :: * -> *) a. Applicative m => a -> M m a
forall (m :: * -> *) a b. Applicative m => M m a -> M m b -> M m a
forall (m :: * -> *) a b. Applicative m => M m a -> M m b -> M m b
forall (m :: * -> *) a b.
Applicative m =>
M m (a -> b) -> M m a -> M m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> M m a -> M m b -> M m c
<* :: M m a -> M m b -> M m a
$c<* :: forall (m :: * -> *) a b. Applicative m => M m a -> M m b -> M m a
*> :: M m a -> M m b -> M m b
$c*> :: forall (m :: * -> *) a b. Applicative m => M m a -> M m b -> M m b
liftA2 :: (a -> b -> c) -> M m a -> M m b -> M m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> M m a -> M m b -> M m c
<*> :: M m (a -> b) -> M m a -> M m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
M m (a -> b) -> M m a -> M m b
pure :: a -> M m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> M m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (M m)
Applicative, Applicative (M m)
a -> M m a
Applicative (M m)
-> (forall a b. M m a -> (a -> M m b) -> M m b)
-> (forall a b. M m a -> M m b -> M m b)
-> (forall a. a -> M m a)
-> Monad (M m)
M m a -> (a -> M m b) -> M m b
M m a -> M m b -> M m b
forall a. a -> M m a
forall a b. M m a -> M m b -> M m b
forall a b. M m a -> (a -> M m b) -> M m b
forall (m :: * -> *). Monad m => Applicative (M m)
forall (m :: * -> *) a. Monad m => a -> M m a
forall (m :: * -> *) a b. Monad m => M m a -> M m b -> M m b
forall (m :: * -> *) a b. Monad m => M m a -> (a -> M m b) -> M m 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
return :: a -> M m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> M m a
>> :: M m a -> M m b -> M m b
$c>> :: forall (m :: * -> *) a b. Monad m => M m a -> M m b -> M m b
>>= :: M m a -> (a -> M m b) -> M m b
$c>>= :: forall (m :: * -> *) a b. Monad m => M m a -> (a -> M m b) -> M m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (M m)
Monad, Monad (M m)
Monad (M m) -> (forall a. (a -> M m a) -> M m a) -> MonadFix (M m)
(a -> M m a) -> M m a
forall a. (a -> M m a) -> M m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (M m)
forall (m :: * -> *) a. MonadFix m => (a -> M m a) -> M m a
mfix :: (a -> M m a) -> M m a
$cmfix :: forall (m :: * -> *) a. MonadFix m => (a -> M m a) -> M m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (M m)
MonadFix, Monad (M m)
Monad (M m)
-> (forall a b. M m a -> M m b -> M m (a, b))
-> (forall a b c. (a -> b -> c) -> M m a -> M m b -> M m c)
-> (forall a b. M m (a, b) -> (M m a, M m b))
-> MonadZip (M m)
M m a -> M m b -> M m (a, b)
M m (a, b) -> (M m a, M m b)
(a -> b -> c) -> M m a -> M m b -> M m c
forall a b. M m a -> M m b -> M m (a, b)
forall a b. M m (a, b) -> (M m a, M m b)
forall a b c. (a -> b -> c) -> M m a -> M m b -> M m c
forall (m :: * -> *).
Monad m
-> (forall a b. m a -> m b -> m (a, b))
-> (forall a b c. (a -> b -> c) -> m a -> m b -> m c)
-> (forall a b. m (a, b) -> (m a, m b))
-> MonadZip m
forall (m :: * -> *). MonadZip m => Monad (M m)
forall (m :: * -> *) a b.
MonadZip m =>
M m a -> M m b -> M m (a, b)
forall (m :: * -> *) a b.
MonadZip m =>
M m (a, b) -> (M m a, M m b)
forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c) -> M m a -> M m b -> M m c
munzip :: M m (a, b) -> (M m a, M m b)
$cmunzip :: forall (m :: * -> *) a b.
MonadZip m =>
M m (a, b) -> (M m a, M m b)
mzipWith :: (a -> b -> c) -> M m a -> M m b -> M m c
$cmzipWith :: forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c) -> M m a -> M m b -> M m c
mzip :: M m a -> M m b -> M m (a, b)
$cmzip :: forall (m :: * -> *) a b.
MonadZip m =>
M m a -> M m b -> M m (a, b)
$cp1MonadZip :: forall (m :: * -> *). MonadZip m => Monad (M m)
MonadZip)
#ifdef AVAIL_semigroupoids
deriving newtype instance Apply m => Apply (M m)
instance Bind m => Bind (M m) where
UnsafeLift m >>- f = UnsafeLift $ m >>- (unM . f)
join (UnsafeLift m) = UnsafeLift $ join $ unM <$> m
#endif
type Effect = (Type -> Type) -> Constraint
class KnownList (Superclasses e) => IsEff (e :: Effect) where
type Superclasses e :: [Effect]
class Eff' (e :: Effect) where
instEffect :: Proxy e
instEffect = [Char] -> Proxy e
forall a. HasCallStack => [Char] -> a
error [Char]
"unimplemented"
type Eff (e :: Effect) = (Eff' e, Effs (Superclasses e))
type family Effs (es :: [Effect]) :: Constraint where
Effs '[] = ()
Effs (e ': es) = (Eff e, Effs es)
newtype InstEff e a = InstEff (Eff' e => a)
rip' :: forall e a. (Eff' e => a) -> a
rip' :: (Eff' e => a) -> a
rip' Eff' e => a
x = InstEff e a -> Proxy Any -> a
forall a b. a -> b
unsafeCoerce ((Eff' e => a) -> InstEff e a
forall (e :: Effect) a. (Eff' e => a) -> InstEff e a
InstEff @e Eff' e => a
x) Proxy Any
forall k (t :: k). Proxy t
Proxy
rip :: forall e a. IsEff e => (Eff e => a) -> a
rip :: (Eff e => a) -> a
rip Eff e => a
x = forall a.
KnownList (Superclasses e) =>
(Effs (Superclasses e) => a) -> a
forall (es :: [Effect]) a. KnownList es => (Effs es => a) -> a
rips @(Superclasses e) ((Effs (Superclasses e) => a) -> a)
-> (Effs (Superclasses e) => a) -> a
forall a b. (a -> b) -> a -> b
$ (Eff' e => a) -> a
forall (e :: Effect) a. (Eff' e => a) -> a
rip' @e Eff e => a
Eff' e => a
x
class KnownList (es :: [Effect]) where
rips :: (Effs es => a) -> a
rips Effs es => a
_ = [Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"unimplemented"
instance KnownList '[] where
rips :: (Effs '[] => a) -> a
rips Effs '[] => a
x = a
Effs '[] => a
x
instance (IsEff e, KnownList es) => KnownList (e ': es) where
rips :: (Effs (e : es) => a) -> a
rips Effs (e : es) => a
x = forall a. KnownList es => (Effs es => a) -> a
forall (es :: [Effect]) a. KnownList es => (Effs es => a) -> a
rips @es ((Effs es => a) -> a) -> (Effs es => a) -> a
forall a b. (a -> b) -> a -> b
$ (Eff e => a) -> a
forall (e :: Effect) a. IsEff e => (Eff e => a) -> a
rip @e Eff e => a
Effs (e : es) => a
x
unM :: M m a -> m a
unM :: M m a -> m a
unM (UnsafeLift m a
m) = m a
m
runM :: forall es m a. KnownList es => (Effs es => M m a) -> m a
runM :: (Effs es => M m a) -> m a
runM Effs es => M m a
m = forall a. KnownList es => (Effs es => a) -> a
forall (es :: [Effect]) a. KnownList es => (Effs es => a) -> a
rips @es ((Effs es => m a) -> m a) -> (Effs es => m a) -> m a
forall a b. (a -> b) -> a -> b
$ M m a -> m a
forall k (m :: k -> *) (a :: k). M m a -> m a
unM M m a
Effs es => M m a
m