Community
Modules 26

Data.Functor.Alt

provisional

class Functor f => Alt f

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 distribution" law of MonadPlus with respect to <.>:

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

IO, Either a, ExceptT e m and STM instead satisfy the "left catch" law:

pure a <!> b = pure a

Maybe and Identity satisfy both "left distribution" and "left catch".

These variations 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

<|> without a required empty

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

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

optional :: (Alt f, Applicative f) => f a -> f (Maybe a)

One or none.

galt :: (Generic1 f, Alt (Rep1 f)) => f a -> f a -> f a

Generic (<!>). Caveats:

  1. Will not compile if f is a sum type.

  2. Any types where the a does not appear must have a Semigroup instance.

module Data.Functor.Apply semigroupoids-6.0.2 · 12 declarations

($>) :: (Functor f) => f a -> b -> f b

Replace every value with the given one.

(<$>) :: (Functor f) => (a -> b) -> f a -> f b

(<*.>) :: (Apply f) => MaybeApply f (a -> b) -> f a -> f b

Apply a possibly-empty-with-unit container of functions to a non-empty container of values.

(<.*>) :: (Apply f) => f (a -> b) -> MaybeApply f a -> f b

Apply a non-empty container of functions to a possibly-empty-with-unit container of values.

(<..>) :: Apply w => w a -> w (a -> b) -> w b

A variant of <.> with the arguments reversed.

gliftF2 :: (Generic1 w, Apply (Rep1 w)) => (a -> b -> c) -> w a -> w b -> w c

Generic liftF2. Caveats:

  1. Will not compile if w is a sum type.

  2. Types in w that do not mention the type variable must be instances of Semigroup.

gliftF3 :: (Generic1 w, Apply (Rep1 w)) => (a -> b -> c -> d) -> w a -> w b -> w c -> w d

Generic liftF3. Caveats are the same as for gliftF2.

liftF3 :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d

Lift a ternary function into a comonad with zipping

class Functor f => Apply f

A strong lax semi-monoidal endofunctor. This is equivalent to an Applicative without pure.

Laws:

('.') '<$>' u '<.>' v '<.>' w = u '<.>' (v '<.>' w)
x '<.>' (f '<$>' y) = ('.' f) '<$>' x '<.>' y
f '<$>' (x '<.>' y) = (f '.') '<$>' x '<.>' y

The laws imply that `.>` and `<.` really ignore their left and right results, respectively, and really return their right and left results, respectively. Specifically,

(mf '<$>' m) '.>' (nf '<$>' n) = nf '<$>' (m '.>' n)
(mf '<$>' m) '<.' (nf '<$>' n) = mf '<$>' (m '<.' n)

(<.>) :: f (a -> b) -> f a -> f b

(.>) :: f a -> f b -> f b

a .> b = const id <$> a <.> b

(<.) :: f a -> f b -> f a

a <. b = const <$> a <.> b

liftF2 :: (a -> b -> c) -> f a -> f b -> f c

Lift a binary function into a comonad with zipping

class Functor (f :: Type -> Type)

fmap :: (a -> b) -> f a -> f b

(<$) :: a -> f b -> f a

newtype MaybeApply f a

Transform an Apply into an Applicative by adding a unit.

Instances

42
  • instance (Alt f, Alt g) => Alt (f :*: g)
  • instance (Alt f, Functor g) => Alt (f :.: g)
  • instance Alt f => Alt (M1 i c f)
  • instance Alt f => Alt (Rec1 f)
  • instance Semigroup c => Alt (K1 i c)

    since 5.3.8

  • instance Alt U1
  • instance Alt V1
  • instance Alt Proxy
  • instance Alt (Either a)
  • instance Alt IO

    This instance does not actually satisfy the (<.>) right distributive law It instead satisfies the "left catch" law

  • instance Alt Identity

    Choose the first option every time. While 'choose the last option' every time is also valid, this instance satisfies more laws.

  • instance Alt []
  • instance Alt Maybe
  • instance MonadPlus m => Alt (WrappedMonad m)
  • instance ArrowPlus a => Alt (WrappedArrow a b)
  • instance Ord k => Alt (Map k)
  • instance Alt IntMap
  • instance Alt Seq
  • instance (Hashable k, Eq k) => Alt (HashMap k)
  • instance Alt NonEmpty
  • instance Alternative f => Alt (WrappedApplicative f)
  • instance Alt f => Alt (IdentityT f)
  • instance Alt f => Alt (ReaderT e f)
  • instance (Functor f, Monad f) => Alt (MaybeT f)
  • instance (Functor f, Monad f, Semigroup e) => Alt (ExceptT e f)
  • instance Alt f => Alt (Strict.StateT e f)
  • instance Alt f => Alt (Lazy.StateT e f)
  • instance Alt f => Alt (Strict.WriterT w f)
  • instance Alt f => Alt (Lazy.WriterT w f)
  • instance (Alt f) => Alt (CPS.WriterT w f)
  • instance Alt f => Alt (Strict.RWST r w s f)
  • instance Alt f => Alt (Lazy.RWST r w s f)
  • instance (Alt f) => Alt (CPS.RWST r w s f)
  • instance Alt f => Alt (Backwards f)
  • instance (Alt f, Functor g) => Alt (Compose f g)
  • instance Alt f => Alt (Lift f)
  • instance (Alt f, Alt g) => Alt (Product f g)
  • instance Alt f => Alt (Reverse f)
  • instance Alt Semigroup.First
  • instance Alt Semigroup.Last
  • instance Alt Monoid.First
  • instance Alt Monoid.Last
Maintainer
Edward Kmett <ekmett@gmail.com>
Portability
portable
Copyright
(C) 2011-2015 Edward Kmett
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 4ac4693dc44e2bb370a93502d1bf29784374032a00ad7b3d02803e3d433c0b16

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.