{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-trustworthy-safe #-}
module Control.Monad.Select
(
MonadSelect (..),
LiftingSelect (..),
)
where
import Control.Monad.Trans.Accum (AccumT)
import Control.Monad.Trans.Class (MonadTrans (lift))
import Control.Monad.Trans.Cont (ContT)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Identity (IdentityT)
import Control.Monad.Trans.Maybe (MaybeT)
import qualified Control.Monad.Trans.RWS.CPS as CPSRWS
import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS
import qualified Control.Monad.Trans.RWS.Strict as StrictRWS
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Trans.Select (SelectT)
import qualified Control.Monad.Trans.Select as Select
import qualified Control.Monad.Trans.State.Lazy as LazyState
import qualified Control.Monad.Trans.State.Strict as StrictState
import qualified Control.Monad.Trans.Writer.CPS as CPSWriter
import qualified Control.Monad.Trans.Writer.Lazy as LazyWriter
import qualified Control.Monad.Trans.Writer.Strict as StrictWriter
import Data.Functor.Identity (Identity)
import Data.Kind (Type)
class (Monad m) => MonadSelect r m | m -> r where
select :: ((a -> r) -> a) -> m a
instance MonadSelect r (SelectT r Identity) where
select :: forall a. ((a -> r) -> a) -> SelectT r Identity a
select = ((a -> r) -> a) -> Select r a
forall a r. ((a -> r) -> a) -> Select r a
Select.select
deriving via
(LiftingSelect MaybeT m)
instance
(MonadSelect r m) =>
MonadSelect r (MaybeT m)
deriving via
(LiftingSelect (ContT r) m)
instance
(MonadSelect r' m) =>
MonadSelect r' (ContT r m)
deriving via
(LiftingSelect (ExceptT e) m)
instance
(MonadSelect r m) =>
MonadSelect r (ExceptT e m)
deriving via
(LiftingSelect IdentityT m)
instance
(MonadSelect r m) =>
MonadSelect r (IdentityT m)
deriving via
(LiftingSelect (ReaderT r) m)
instance
(MonadSelect r' m) =>
MonadSelect r' (ReaderT r m)
deriving via
(LiftingSelect (LazyState.StateT s) m)
instance
(MonadSelect w m) =>
MonadSelect w (LazyState.StateT s m)
deriving via
(LiftingSelect (StrictState.StateT s) m)
instance
(MonadSelect w m) =>
MonadSelect w (StrictState.StateT s m)
deriving via
(LiftingSelect (CPSWriter.WriterT w) m)
instance
(MonadSelect w' m) =>
MonadSelect w' (CPSWriter.WriterT w m)
deriving via
(LiftingSelect (LazyWriter.WriterT w) m)
instance
(MonadSelect w' m, Monoid w) =>
MonadSelect w' (LazyWriter.WriterT w m)
deriving via
(LiftingSelect (StrictWriter.WriterT w) m)
instance
(MonadSelect w' m, Monoid w) =>
MonadSelect w' (StrictWriter.WriterT w m)
deriving via
(LiftingSelect (CPSRWS.RWST r w s) m)
instance
(MonadSelect w' m) =>
MonadSelect w' (CPSRWS.RWST r w s m)
deriving via
(LiftingSelect (LazyRWS.RWST r w s) m)
instance
(MonadSelect w' m, Monoid w) =>
MonadSelect w' (LazyRWS.RWST r w s m)
deriving via
(LiftingSelect (StrictRWS.RWST r w s) m)
instance
(MonadSelect w' m, Monoid w) =>
MonadSelect w' (StrictRWS.RWST r w s m)
deriving via
(LiftingSelect (AccumT w) m)
instance
(MonadSelect r m, Monoid w) =>
MonadSelect r (AccumT w m)
newtype LiftingSelect (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) (a :: Type)
= LiftingSelect (t m a)
deriving
(
(forall a b.
(a -> b) -> LiftingSelect t m a -> LiftingSelect t m b)
-> (forall a b. a -> LiftingSelect t m b -> LiftingSelect t m a)
-> Functor (LiftingSelect t m)
forall a b. a -> LiftingSelect t m b -> LiftingSelect t m a
forall a b. (a -> b) -> LiftingSelect t m a -> LiftingSelect t m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor (t m) =>
a -> LiftingSelect t m b -> LiftingSelect t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor (t m) =>
(a -> b) -> LiftingSelect t m a -> LiftingSelect t m b
$cfmap :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor (t m) =>
(a -> b) -> LiftingSelect t m a -> LiftingSelect t m b
fmap :: forall a b. (a -> b) -> LiftingSelect t m a -> LiftingSelect t m b
$c<$ :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor (t m) =>
a -> LiftingSelect t m b -> LiftingSelect t m a
<$ :: forall a b. a -> LiftingSelect t m b -> LiftingSelect t m a
Functor,
Functor (LiftingSelect t m)
Functor (LiftingSelect t m) =>
(forall a. a -> LiftingSelect t m a)
-> (forall a b.
LiftingSelect t m (a -> b)
-> LiftingSelect t m a -> LiftingSelect t m b)
-> (forall a b c.
(a -> b -> c)
-> LiftingSelect t m a
-> LiftingSelect t m b
-> LiftingSelect t m c)
-> (forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b)
-> (forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m a)
-> Applicative (LiftingSelect t m)
forall a. a -> LiftingSelect t m a
forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m a
forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
forall a b.
LiftingSelect t m (a -> b)
-> LiftingSelect t m a -> LiftingSelect t m b
forall a b c.
(a -> b -> c)
-> LiftingSelect t m a
-> LiftingSelect t m b
-> LiftingSelect t 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 (t :: (* -> *) -> * -> *) (m :: * -> *).
Applicative (t m) =>
Functor (LiftingSelect t m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative (t m) =>
a -> LiftingSelect t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m (a -> b)
-> LiftingSelect t m a -> LiftingSelect t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Applicative (t m) =>
(a -> b -> c)
-> LiftingSelect t m a
-> LiftingSelect t m b
-> LiftingSelect t m c
$cpure :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative (t m) =>
a -> LiftingSelect t m a
pure :: forall a. a -> LiftingSelect t m a
$c<*> :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m (a -> b)
-> LiftingSelect t m a -> LiftingSelect t m b
<*> :: forall a b.
LiftingSelect t m (a -> b)
-> LiftingSelect t m a -> LiftingSelect t m b
$cliftA2 :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Applicative (t m) =>
(a -> b -> c)
-> LiftingSelect t m a
-> LiftingSelect t m b
-> LiftingSelect t m c
liftA2 :: forall a b c.
(a -> b -> c)
-> LiftingSelect t m a
-> LiftingSelect t m b
-> LiftingSelect t m c
$c*> :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
*> :: forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
$c<* :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m a
<* :: forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m a
Applicative,
Applicative (LiftingSelect t m)
Applicative (LiftingSelect t m) =>
(forall a b.
LiftingSelect t m a
-> (a -> LiftingSelect t m b) -> LiftingSelect t m b)
-> (forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b)
-> (forall a. a -> LiftingSelect t m a)
-> Monad (LiftingSelect t m)
forall a. a -> LiftingSelect t m a
forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
forall a b.
LiftingSelect t m a
-> (a -> LiftingSelect t m b) -> LiftingSelect t 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
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
Monad (t m) =>
Applicative (LiftingSelect t m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad (t m) =>
a -> LiftingSelect t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad (t m) =>
LiftingSelect t m a
-> (a -> LiftingSelect t m b) -> LiftingSelect t m b
$c>>= :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad (t m) =>
LiftingSelect t m a
-> (a -> LiftingSelect t m b) -> LiftingSelect t m b
>>= :: forall a b.
LiftingSelect t m a
-> (a -> LiftingSelect t m b) -> LiftingSelect t m b
$c>> :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad (t m) =>
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
>> :: forall a b.
LiftingSelect t m a -> LiftingSelect t m b -> LiftingSelect t m b
$creturn :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad (t m) =>
a -> LiftingSelect t m a
return :: forall a. a -> LiftingSelect t m a
Monad
)
via (t m)
instance (MonadTrans t, MonadSelect r m, Monad (t m)) => MonadSelect r (LiftingSelect t m) where
select :: forall a. ((a -> r) -> a) -> LiftingSelect t m a
select (a -> r) -> a
f = t m a -> LiftingSelect t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
t m a -> LiftingSelect t m a
LiftingSelect (t m a -> LiftingSelect t m a)
-> (m a -> t m a) -> m a -> LiftingSelect t m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> t m a
forall (m :: * -> *) a. Monad m => m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> LiftingSelect t m a) -> m a -> LiftingSelect t m a
forall a b. (a -> b) -> a -> b
$ ((a -> r) -> a) -> m a
forall a. ((a -> r) -> a) -> m a
forall r (m :: * -> *) a. MonadSelect r m => ((a -> r) -> a) -> m a
select (a -> r) -> a
f