Copyright | (C) 2011-2015 Edward Kmett |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Stability | provisional |

Portability | portable |

Safe Haskell | Trustworthy |

Language | Haskell98 |

- class Functor f => Alt f where
- module Data.Functor.Apply

# Documentation

class Functor f => Alt f where #

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

, and `ErrorT`

e m`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)

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

`<|>`

without a required `empty`

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

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

Alt [] # | |

Alt Maybe # | |

Alt IO # | This instance does not actually satisfy the ( |

Alt V1 # | |

Alt U1 # | |

Alt Option # | |

Alt NonEmpty # | |

Alt IntMap # | |

Alt Seq # | |

Alt (Either a) # | |

Alt f => Alt (Rec1 f) # | |

MonadPlus m => Alt (WrappedMonad m) # | |

Alt (Proxy *) # | |

Ord k => Alt (Map k) # | |

Alt f => Alt (Lift f) # | |

(Bind f, Monad f) => Alt (MaybeT f) # | |

Apply f => Alt (ListT f) # | |

Alternative f => Alt (WrappedApplicative f) # | |

(Alt f, Alt g) => Alt ((:*:) f g) # | |

ArrowPlus a => Alt (WrappedArrow a b) # | |

Alt f => Alt (IdentityT * f) # | |

Alt f => Alt (Reverse * f) # | |

Alt f => Alt (Backwards * f) # | |

Alt f => Alt (WriterT w f) # | |

Alt f => Alt (WriterT w f) # | |

Alt f => Alt (StateT e f) # | |

Alt f => Alt (StateT e f) # | |

(Bind f, Monad f, Semigroup e) => Alt (ExceptT e f) # | |

(Bind f, Monad f) => Alt (ErrorT e f) # | |

Alt f => Alt (Static f a) # | |

Alt f => Alt (M1 i c f) # | |

(Alt f, Alt g) => Alt (Product * f g) # | |

Alt f => Alt (ReaderT * e f) # | |

(Alt f, Functor g) => Alt (Compose * * f g) # | |

Alt f => Alt (RWST r w s f) # | |

Alt f => Alt (RWST r w s f) # | |

module Data.Functor.Apply