{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Capability.Reflection
(
interpret_
, interpret
, Reified
, Reflected (..)
, reified
, Reifies
, reify
, reflect
, Proxy (..)
) where
import Capability.Constraints
import Capability.Derive
import Data.Kind (Type)
import Data.Proxy
import Data.Reflection
interpret_ ::
forall tag c m a.
( Monad m,
forall s. Reifies s (Reified tag c m) => c (Reflected s c m)
) =>
Reified tag c m ->
(forall m'. c m' => m' a) ->
m a
interpret_ :: Reified tag c m -> (forall (m' :: * -> *). c m' => m' a) -> m a
interpret_ = forall k (tag :: k) (cs :: [Capability]) (c :: Capability)
(m :: * -> *) a.
(Monad m, All cs m,
forall s. Reifies s (Reified tag c m) => c (Reflected s c m)) =>
Reified tag c m
-> (forall (m' :: * -> *). All (c : cs) m' => m' a) -> m a
forall (m :: * -> *) a.
(Monad m, All '[] m,
forall s. Reifies s (Reified tag c m) => c (Reflected s c m)) =>
Reified tag c m
-> (forall (m' :: * -> *). All '[c] m' => m' a) -> m a
interpret @tag @'[] @c
{-# INLINE interpret_ #-}
interpret ::
forall tag (cs :: [Capability]) c m a.
( Monad m,
All cs m,
forall s. Reifies s (Reified tag c m) => c (Reflected s c m)
) =>
Reified tag c m ->
(forall m'. All (c ': cs) m' => m' a) ->
m a
interpret :: Reified tag c m
-> (forall (m' :: * -> *). All (c : cs) m' => m' a) -> m a
interpret Reified tag c m
dict forall (m' :: * -> *). All (c : cs) m' => m' a
action =
Reified tag c m
-> (forall s. Reifies s (Reified tag c m) => Proxy s -> m a) -> m a
forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify Reified tag c m
dict ((forall s. Reifies s (Reified tag c m) => Proxy s -> m a) -> m a)
-> (forall s. Reifies s (Reified tag c m) => Proxy s -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ \(Proxy s
_ :: Proxy s) ->
(forall (m' :: * -> *). (All '[c] m', All cs m') => m' a) -> m a
forall (t :: (* -> *) -> * -> *) (derived :: [Capability])
(ambient :: [Capability]) (m :: * -> *) a.
(forall x. Coercible (t m x) (m x), All derived (t m),
All ambient m) =>
(forall (m' :: * -> *). (All derived m', All ambient m') => m' a)
-> m a
derive @(Reflected s c) @'[c] @cs forall (m' :: * -> *). All (c : cs) m' => m' a
forall (m' :: * -> *). (All '[c] m', All cs m') => m' a
action
{-# INLINE interpret #-}
data family Reified (tag :: k) (c :: Capability) (m :: Type -> Type)
newtype Reflected (s :: Type) (c :: Capability) (m :: Type -> Type) (a :: Type) = Reflect (m a)
deriving (a -> Reflected s c m b -> Reflected s c m a
(a -> b) -> Reflected s c m a -> Reflected s c m b
(forall a b. (a -> b) -> Reflected s c m a -> Reflected s c m b)
-> (forall a b. a -> Reflected s c m b -> Reflected s c m a)
-> Functor (Reflected s c m)
forall a b. a -> Reflected s c m b -> Reflected s c m a
forall a b. (a -> b) -> Reflected s c m a -> Reflected s c m b
forall s (c :: Capability) (m :: * -> *) a b.
Functor m =>
a -> Reflected s c m b -> Reflected s c m a
forall s (c :: Capability) (m :: * -> *) a b.
Functor m =>
(a -> b) -> Reflected s c m a -> Reflected s c m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Reflected s c m b -> Reflected s c m a
$c<$ :: forall s (c :: Capability) (m :: * -> *) a b.
Functor m =>
a -> Reflected s c m b -> Reflected s c m a
fmap :: (a -> b) -> Reflected s c m a -> Reflected s c m b
$cfmap :: forall s (c :: Capability) (m :: * -> *) a b.
Functor m =>
(a -> b) -> Reflected s c m a -> Reflected s c m b
Functor, Functor (Reflected s c m)
a -> Reflected s c m a
Functor (Reflected s c m)
-> (forall a. a -> Reflected s c m a)
-> (forall a b.
Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b)
-> (forall a b c.
(a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c m c)
-> (forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m b)
-> (forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m a)
-> Applicative (Reflected s c m)
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
Reflected s c m a -> Reflected s c m b -> Reflected s c m a
Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b
(a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c m c
forall a. a -> Reflected s c m a
forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m a
forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
forall a b.
Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b
forall a b c.
(a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c m c
forall s (c :: Capability) (m :: * -> *).
Applicative m =>
Functor (Reflected s c m)
forall s (c :: Capability) (m :: * -> *) a.
Applicative m =>
a -> Reflected s c m a
forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m a
forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b
forall s (c :: Capability) (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c 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
<* :: Reflected s c m a -> Reflected s c m b -> Reflected s c m a
$c<* :: forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m a
*> :: Reflected s c m a -> Reflected s c m b -> Reflected s c m b
$c*> :: forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
liftA2 :: (a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c m c
$cliftA2 :: forall s (c :: Capability) (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> Reflected s c m a -> Reflected s c m b -> Reflected s c m c
<*> :: Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b
$c<*> :: forall s (c :: Capability) (m :: * -> *) a b.
Applicative m =>
Reflected s c m (a -> b) -> Reflected s c m a -> Reflected s c m b
pure :: a -> Reflected s c m a
$cpure :: forall s (c :: Capability) (m :: * -> *) a.
Applicative m =>
a -> Reflected s c m a
$cp1Applicative :: forall s (c :: Capability) (m :: * -> *).
Applicative m =>
Functor (Reflected s c m)
Applicative, Applicative (Reflected s c m)
a -> Reflected s c m a
Applicative (Reflected s c m)
-> (forall a b.
Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c m b)
-> (forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m b)
-> (forall a. a -> Reflected s c m a)
-> Monad (Reflected s c m)
Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c m b
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
forall a. a -> Reflected s c m a
forall a b.
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
forall a b.
Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c m b
forall s (c :: Capability) (m :: * -> *).
Monad m =>
Applicative (Reflected s c m)
forall s (c :: Capability) (m :: * -> *) a.
Monad m =>
a -> Reflected s c m a
forall s (c :: Capability) (m :: * -> *) a b.
Monad m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
forall s (c :: Capability) (m :: * -> *) a b.
Monad m =>
Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c 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 -> Reflected s c m a
$creturn :: forall s (c :: Capability) (m :: * -> *) a.
Monad m =>
a -> Reflected s c m a
>> :: Reflected s c m a -> Reflected s c m b -> Reflected s c m b
$c>> :: forall s (c :: Capability) (m :: * -> *) a b.
Monad m =>
Reflected s c m a -> Reflected s c m b -> Reflected s c m b
>>= :: Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c m b
$c>>= :: forall s (c :: Capability) (m :: * -> *) a b.
Monad m =>
Reflected s c m a -> (a -> Reflected s c m b) -> Reflected s c m b
$cp1Monad :: forall s (c :: Capability) (m :: * -> *).
Monad m =>
Applicative (Reflected s c m)
Monad)
reified :: forall s tag c m. Reifies s (Reified tag c m) => Reified tag c m
reified :: Reified tag c m
reified = Proxy s -> Reified tag c m
forall k (s :: k) a (proxy :: k -> *). Reifies s a => proxy s -> a
reflect (Proxy s
forall k (t :: k). Proxy t
Proxy @s)
{-# INLINE reified #-}