{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Trustworthy #-}
module Grisette.Lib.Control.Monad
(
mrgReturnWithStrategy,
mrgBindWithStrategy,
mrgReturn,
(>>=~),
(>>~),
mrgFoldM,
mrgMzero,
mrgMplus,
mrgFmap,
)
where
import Control.Monad
import Grisette.Core.Control.Monad.Union
import Grisette.Core.Data.Class.Bool
import Grisette.Core.Data.Class.Mergeable
import Grisette.Core.Data.Class.SimpleMergeable
import Grisette.Lib.Data.Foldable
mrgReturnWithStrategy :: (MonadUnion u) => MergingStrategy a -> a -> u a
mrgReturnWithStrategy :: forall (u :: * -> *) a.
MonadUnion u =>
MergingStrategy a -> a -> u a
mrgReturnWithStrategy MergingStrategy a
s = forall (u :: * -> *) a.
UnionLike u =>
MergingStrategy a -> u a -> u a
mergeWithStrategy MergingStrategy a
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return
{-# INLINE mrgReturnWithStrategy #-}
mrgBindWithStrategy :: (MonadUnion u) => MergingStrategy b -> u a -> (a -> u b) -> u b
mrgBindWithStrategy :: forall (u :: * -> *) b a.
MonadUnion u =>
MergingStrategy b -> u a -> (a -> u b) -> u b
mrgBindWithStrategy MergingStrategy b
s u a
a a -> u b
f = forall (u :: * -> *) a.
UnionLike u =>
MergingStrategy a -> u a -> u a
mergeWithStrategy MergingStrategy b
s forall a b. (a -> b) -> a -> b
$ u a
a forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> u b
f
{-# INLINE mrgBindWithStrategy #-}
mrgReturn :: (MonadUnion u, Mergeable a) => a -> u a
mrgReturn :: forall (u :: * -> *) a. (MonadUnion u, Mergeable a) => a -> u a
mrgReturn = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return
{-# INLINE mrgReturn #-}
(>>=~) :: (MonadUnion u, Mergeable b) => u a -> (a -> u b) -> u b
u a
a >>=~ :: forall (u :: * -> *) b a.
(MonadUnion u, Mergeable b) =>
u a -> (a -> u b) -> u b
>>=~ a -> u b
f = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall a b. (a -> b) -> a -> b
$ u a
a forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> u b
f
{-# INLINE (>>=~) #-}
mrgFoldM :: (MonadUnion m, Mergeable b, Foldable t) => (b -> a -> m b) -> b -> t a -> m b
mrgFoldM :: forall (m :: * -> *) b (t :: * -> *) a.
(MonadUnion m, Mergeable b, Foldable t) =>
(b -> a -> m b) -> b -> t a -> m b
mrgFoldM = forall (m :: * -> *) b (t :: * -> *) a.
(MonadUnion m, Mergeable b, Foldable t) =>
(b -> a -> m b) -> b -> t a -> m b
mrgFoldlM
{-# INLINE mrgFoldM #-}
(>>~) :: forall m a b. (MonadUnion m, Mergeable b) => m a -> m b -> m b
m a
a >>~ :: forall (m :: * -> *) a b.
(MonadUnion m, Mergeable b) =>
m a -> m b -> m b
>>~ m b
f = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) b a.
(MonadUnion f, Mergeable b, Functor f) =>
(a -> b) -> f a -> f b
mrgFmap (forall a b. a -> b -> a
const ()) m a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m b
f
{-# INLINE (>>~) #-}
mrgMzero :: forall m a. (MonadUnion m, Mergeable a, MonadPlus m) => m a
mrgMzero :: forall (m :: * -> *) a.
(MonadUnion m, Mergeable a, MonadPlus m) =>
m a
mrgMzero = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE mrgMzero #-}
mrgMplus :: forall m a. (MonadUnion m, Mergeable a, MonadPlus m) => m a -> m a -> m a
mrgMplus :: forall (m :: * -> *) a.
(MonadUnion m, Mergeable a, MonadPlus m) =>
m a -> m a -> m a
mrgMplus m a
a m a
b = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus m a
a m a
b
{-# INLINE mrgMplus #-}
mrgFmap :: (MonadUnion f, Mergeable b, Functor f) => (a -> b) -> f a -> f b
mrgFmap :: forall (f :: * -> *) b a.
(MonadUnion f, Mergeable b, Functor f) =>
(a -> b) -> f a -> f b
mrgFmap a -> b
f f a
a = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f f a
a
{-# INLINE mrgFmap #-}