monad-ideals-0.1.0.0: Ideal Monads and coproduct of them
Copyright(C) 2008 Edward Kmett (C) 2024 Koji Miyazato
LicenseBSD-style (see the file LICENSE)
MaintainerKoji Miyazato <viercc@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Ideal

Description

 
Synopsis

Ideal Monads

class (Bind m0, Isolated m0) => MonadIdeal m0 where Source #

m0 is the "ideal part" of an ideal monad.

Laws

Methods inherited from superclasses must be equivalent to the canocical ones.

Methods

idealBind :: m0 a -> (a -> Ideal m0 b) -> m0 b infixl 1 Source #

Instances

Instances details
MonadIdeal TwoOrMore Source #
Ideal TwoOrMore ~ NonEmpty
Instance details

Defined in Data.List.TwoOrMore

Methods

idealBind :: TwoOrMore a -> (a -> Ideal TwoOrMore b) -> TwoOrMore b Source #

Monad m => MonadIdeal (WrappedMonad m) Source #

Any Monad m can be an ideal of Ideal m

Instance details

Defined in Control.Monad.Ideal

Methods

idealBind :: WrappedMonad m a -> (a -> Ideal (WrappedMonad m) b) -> WrappedMonad m b Source #

MonadIdeal (KeepLeft c) Source #
Ideal (KeepLeft c) a ~ Either c a
Instance details

Defined in Data.Functor.KeepLeft

Methods

idealBind :: KeepLeft c a -> (a -> Ideal (KeepLeft c) b) -> KeepLeft c b Source #

Semigroup s => MonadIdeal ((,) s) Source #
Ideal ((,) s) ~ (,) (Maybe s)
Instance details

Defined in Control.Monad.Ideal

Methods

idealBind :: (s, a) -> (a -> Ideal ((,) s) b) -> (s, b) Source #

(MonadIdeal m0, MonadIdeal n0) => MonadIdeal (m0 :+ n0) Source # 
Instance details

Defined in Control.Monad.Coproduct

Methods

idealBind :: (m0 :+ n0) a -> (a -> Ideal (m0 :+ n0) b) -> (m0 :+ n0) b Source #

idealize :: MonadIdeal m0 => m0 (Ideal m0 a) -> m0 a Source #

type Ideal = Unite Source #

Ideal monad is a special case of Unite m0

ideal :: Either a (m0 a) -> Ideal m0 a Source #

Constructor of Ideal, for backward compatibility

runIdeal :: Ideal m0 a -> Either a (m0 a) Source #

Deconstructor of Ideal, for backward compatibility

hoistIdeal :: (forall a. m0 a -> n a) -> Ideal m0 b -> Ideal n b Source #

Alias of hoistUnite for naming consistently

destroyIdeal :: (m0 a -> a) -> Ideal m0 a -> a Source #

bindDefault :: MonadIdeal m0 => m0 a -> (a -> m0 b) -> m0 b Source #

impureBindDefault :: MonadIdeal m0 => m0 a -> (a -> Unite m0 b) -> Unite m0 b Source #

Relation between MonadIdeal, Bind, and Isolated

MonadIdeal is a requirement stronger than both of Bind and Isolated. In fact, these subset relations hold.

  • Every MonadIdeal is Bind
  • Every MonadIdeal is Isolated

These are strict subset relation and neither of three classes can be dropped.

  • NotOne is both Bind and Isolated, but not MonadIdeal.
  • NullBind c is Bind but can't be Isolated, because Unite (NullBind c) can't be a Monad in a compatible way.

    newtype NullBind c a = NullBind (Maybe c)
    instance Bind (NullBind c a) where
      _ >>- _ = NullBind Nothing
    
  • Toggle shown below is Isolated, but can't be a Bind in a compatible way.

    newtype Toggle a = Toggle a
      deriving Functor
    
    instance Isolated Toggle where
      impureBind (Toggle a) k = case k a of
        Unite (Left b)           -> Unite (Right (Toggle b))
        Unite (Right (Toggle b)) -> Unite (Left b)