{-# LANGUAGE AllowAmbiguousTypes #-}
module Data.Effect.Provider where
import Data.Effect.Key (type (##>))
import Data.Functor.Identity (Identity, runIdentity)
data Provider' ctx i b (f :: Type -> Type) (a :: Type) where
Provide
:: i
-> ((forall x. f x -> b x) -> b a)
-> Provider' ctx i b f (ctx a)
makeEffectH [''Provider']
data ProviderKey ctx i
type Provider ctx i b = ProviderKey ctx i ##> Provider' ctx i b
type Provider_ i b = ProviderKey Identity i ##> Provider' Identity i b
infix 2 .!
(.!)
:: forall i f a b
. ( SendHOEBy (ProviderKey Identity i) (Provider' Identity i b) f
, Functor f
)
=> i
-> ((f ~> b) -> b a)
-> f a
i
i .! :: forall i (f :: * -> *) a (b :: * -> *).
(SendHOEBy (ProviderKey Identity i) (Provider' Identity i b) f,
Functor f) =>
i -> ((f ~> b) -> b a) -> f a
.! (f ~> b) -> b a
f = Identity a -> a
forall a. Identity a -> a
runIdentity (Identity a -> a) -> f (Identity a) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall {k} (key :: k) i (b :: * -> *) a (ctx :: * -> *)
(f :: * -> *).
SendHOEBy key (Provider' ctx i b) f =>
i -> ((forall x. f x -> b x) -> b a) -> f (ctx a)
forall key i (b :: * -> *) a (ctx :: * -> *) (f :: * -> *).
SendHOEBy key (Provider' ctx i b) f =>
i -> ((forall x. f x -> b x) -> b a) -> f (ctx a)
provide'' @(ProviderKey Identity i) i
i (f ~> b) -> b a
f
{-# INLINE (.!) #-}
infix 2 ..!
(..!)
:: forall ctx i f a b
. (SendHOEBy (ProviderKey ctx i) (Provider' ctx i b) f)
=> i
-> ((f ~> b) -> b a)
-> f (ctx a)
i
i ..! :: forall (ctx :: * -> *) i (f :: * -> *) a (b :: * -> *).
SendHOEBy (ProviderKey ctx i) (Provider' ctx i b) f =>
i -> ((f ~> b) -> b a) -> f (ctx a)
..! (f ~> b) -> b a
f = forall {k} (key :: k) i (b :: * -> *) a (ctx :: * -> *)
(f :: * -> *).
SendHOEBy key (Provider' ctx i b) f =>
i -> ((forall x. f x -> b x) -> b a) -> f (ctx a)
forall key i (b :: * -> *) a (ctx :: * -> *) (f :: * -> *).
SendHOEBy key (Provider' ctx i b) f =>
i -> ((forall x. f x -> b x) -> b a) -> f (ctx a)
provide'' @(ProviderKey ctx i) i
i (f ~> b) -> b a
f
{-# INLINE (..!) #-}