semigroupoids-5.0.1: Semigroupoids: Category sans id

Copyright (C) 2011-2015 Edward Kmett BSD-style (see the file LICENSE) Edward Kmett provisional portable Safe Haskell98

Data.Functor.Alt

Description

Synopsis

Documentation

class Functor f => Alt f where Source

Laws:

<!> is associative:             (a <!> b) <!> c = a <!> (b <!> c)
<\$> left-distributes over <!>:  f <\$> (a <!> b) = (f <\$> a) <!> (f <\$> b)

If extended to an Alternative then <!> should equal <|>.

Ideally, an instance of Alt also satisfies the "left distributon" law of MonadPlus with respect to <.>:

<.> right-distributes over <!>: (a <!> b) <.> c = (a <.> c) <!> (b <.> c)

But Maybe, IO, Either a, ErrorT e m, and STM satisfy the alternative "left catch" law instead:

pure a <!> b = pure a

However, this variation cannot be stated purely in terms of the dependencies of Alt.

When and if MonadPlus is successfully refactored, this class should also be refactored to remove these instances.

The right distributive law should extend in the cases where the a Bind or Monad is provided to yield variations of the right distributive law:

(m <!> n) >>- f = (m >>- f) <!> (m >>- f)
(m <!> n) >>= f = (m >>= f) <!> (m >>= f)

Minimal complete definition

(<!>)

Methods

(<!>) :: f a -> f a -> f a infixl 3 Source

<|> without a required empty

some :: Applicative f => f a -> f [a] Source

many :: Applicative f => f a -> f [a] Source

Instances

 Alt [] Source Source This instance does not actually satisfy the (<.>) right distributive law It instead satisfies the Left-Catch law Source Source Source Source Source Alt (Either a) Source MonadPlus m => Alt (WrappedMonad m) Source Alt f => Alt (IdentityT f) Source Ord k => Alt (Map k) Source Alt f => Alt (Reverse f) Source Alt f => Alt (Backwards f) Source (Bind f, Monad f) => Alt (MaybeT f) Source Apply f => Alt (ListT f) Source Alt f => Alt (Lift f) Source Source ArrowPlus a => Alt (WrappedArrow a b) Source (Alt f, Alt g) => Alt (Product f g) Source (Alt f, Functor g) => Alt (Compose f g) Source Alt f => Alt (WriterT w f) Source Alt f => Alt (WriterT w f) Source (Bind f, Monad f) => Alt (ErrorT e f) Source (Bind f, Monad f, Semigroup e) => Alt (ExceptT e f) Source Alt f => Alt (StateT e f) Source Alt f => Alt (StateT e f) Source Alt f => Alt (ReaderT e f) Source Alt f => Alt (Static f a) Source Alt f => Alt (RWST r w s f) Source Alt f => Alt (RWST r w s f) Source