An applicative functor has more structure than a [[functor]] but less than a [[monad]]. See the Haddock docs for [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Applicative.html <hask>Control.Applicative</hask>].

An applicative functor has more structure than a [[functor]] but less than a [[monad]]. See the Haddock docs for [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Applicative.html <hask>Control.Applicative</hask>].

+

+

== Example ==

It has turned out that many applications do not require monad functionality but only those of applicative functors.

It has turned out that many applications do not require monad functionality but only those of applicative functors.

Line 10:

Line 12:

else putStrLn ("You entered " ++ text)

else putStrLn ("You entered " ++ text)

</haskell>

</haskell>

−

This is obviously necessary is some cases, but in other cases it is disadvantageous.

+

This is obviously necessary in some cases, but in other cases it is disadvantageous.

could not only open dialogs and windows but could also register come cleanup routine in the

CleanIO

.

runAndCleanup

would first run the opening actions and afterwards the required cleanup actions.

I.e. if the dialog was opened, the dialog must be closed, but not the window.
That is, the cleanup procedure depends on the outcomes of earlier actions.

Now consider the slightly different task, where functions shall register initialization routines
that shall be run before the actual action takes place.
(See the original discussion started by Michael T. Richter in Haskell-Cafe:
Practical Haskell Question)
This is impossible in the monadic framework.

Consider the example above where the choice between

openDialog

and

openWindow

depends on the outcome of

getLine

.
You cannot run initialization code for either

openDialog

or

openWindow

,
because you do not know which one will be called before executing

getLine

.

If you eliminate this dependency, you end up in an applicative functor
and there you can do the initialization trick.
You could write