Copyright | (C) 2008 Edward Kmett (C) 2024 Koji Miyazato |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Koji Miyazato <viercc@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Impure part isolated from a Monad
class Functor m0 => Isolated m0 where Source #
Isolated m0
is a Functor
which can be thought of as an impure part of a Monad
.
Examples
NotOne
isIsolated
by being the list monad ('[]') minus singleton lists, thepure
part of the list monad.
Non-example
Not every Monad
can be isolated its pure and impure parts as the sum of functors.
For example, the reader monad cannot be written as a sum of two functors.
Laws
impureBind
must be implemented so that the Monad (Unite m0)
instance derived from
it is lawful.
return a = Unite (Left a) Unite (Left a) >>= k = k a Unite (Right ma) >>= k = ma `impureBind` k
Translating the Monad
laws on Unite m0
in terms of impureBind
,
the following equations are the Isolated
laws on its own.
(Right identity)
ma `impureBind` Unite . Left === Unite (Right ma)
(Associativity)
(ma `impureBind` f) `impureBind` g === ma
impureBind
a -> either g (`impureBind` g) (runUnite fa)
impureBind :: m0 a -> (a -> Unite m0 b) -> Unite m0 b infixl 1 Source #
Instances
Isolated NotOne Source # | |
Defined in Data.List.NotOne | |
Isolated TwoOrMore Source # | |
Defined in Data.List.TwoOrMore | |
Monad m => Isolated (WrappedMonad m) Source # | |
Defined in Control.Monad.Isolated impureBind :: WrappedMonad m a -> (a -> Unite (WrappedMonad m) b) -> Unite (WrappedMonad m) b Source # | |
Isolated (Proxy :: Type -> Type) Source # | |
Defined in Control.Monad.Isolated | |
Isolated (KeepLeft c) Source # | |
Defined in Data.Functor.KeepLeft | |
Semigroup s => Isolated ((,) s) Source # | |
Defined in Control.Monad.Isolated | |
(Isolated m0, Isolated n0) => Isolated (m0 :+ n0) Source # | |
Defined in Control.Monad.Coproduct |
(Re)Unite a Monad from pure and impure parts
Instances
Foldable g => Foldable (Unite g) Source # | |
Defined in Control.Monad.Isolated fold :: Monoid m => Unite g m -> m # foldMap :: Monoid m => (a -> m) -> Unite g a -> m # foldMap' :: Monoid m => (a -> m) -> Unite g a -> m # foldr :: (a -> b -> b) -> b -> Unite g a -> b # foldr' :: (a -> b -> b) -> b -> Unite g a -> b # foldl :: (b -> a -> b) -> b -> Unite g a -> b # foldl' :: (b -> a -> b) -> b -> Unite g a -> b # foldr1 :: (a -> a -> a) -> Unite g a -> a # foldl1 :: (a -> a -> a) -> Unite g a -> a # elem :: Eq a => a -> Unite g a -> Bool # maximum :: Ord a => Unite g a -> a # minimum :: Ord a => Unite g a -> a # | |
Foldable1 g => Foldable1 (Unite g) Source # | |
Defined in Control.Monad.Isolated fold1 :: Semigroup m => Unite g m -> m # foldMap1 :: Semigroup m => (a -> m) -> Unite g a -> m # foldMap1' :: Semigroup m => (a -> m) -> Unite g a -> m # toNonEmpty :: Unite g a -> NonEmpty a # maximum :: Ord a => Unite g a -> a # minimum :: Ord a => Unite g a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Unite g a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Unite g a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Unite g a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Unite g a -> b # | |
Traversable g => Traversable (Unite g) Source # | |
Isolated m0 => Applicative (Unite m0) Source # | |
Functor g => Functor (Unite g) Source # | |
Isolated m0 => Monad (Unite m0) Source # | |
Isolated m0 => Apply (Unite m0) Source # | |
Isolated m0 => Bind (Unite m0) Source # | |
Traversable1 g => Traversable1 (Unite g) Source # | |
(Read a, Read (f a)) => Read (Unite f a) Source # | |
(Show a, Show (f a)) => Show (Unite f a) Source # | |
(Eq a, Eq (f a)) => Eq (Unite f a) Source # | |
(Ord a, Ord (f a)) => Ord (Unite f a) Source # | |
Defined in Control.Monad.Isolated |
hoistUnite :: (forall a. f a -> g a) -> Unite f b -> Unite g b Source #