Applicative functor
From HaskellWiki
(Difference between revisions)
m (Category) |
(Monad vs. applicative functor) |
||
| Line 1: | Line 1: | ||
[[Category:Glossary]] | [[Category:Glossary]] | ||
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>]. | ||
| + | |||
| + | It has turned out that many applications do not require monad functionality but only those of applicative functors. | ||
| + | Monads allow you to run actions depending on the outcomes of earlier actions. | ||
| + | <haskell> | ||
| + | do text <- getLine | ||
| + | if null text | ||
| + | then putStrLn "You refuse to enter something?" | ||
| + | else putStrLn ("You entered " ++ text) | ||
| + | </haskell> | ||
| + | This is obviously necessary is some cases, but in other cases it is disadvantageous. | ||
| + | <!-- | ||
| + | Consider an extended IO monad which handles automated closing of allocated resources | ||
| + | This is possible with a monad. | ||
| + | |||
| + | In contrast, a monad which handles allocation of resources, that are needed later, is impossible. | ||
| + | |||
| + | See Haskell-Cafe discussion. | ||
| + | --> | ||
Revision as of 07:42, 5 November 2007
An applicative functor has more structure than a functor but less than a monad. See the Haddock docs for <div class="inline-code">Control.Applicative
It has turned out that many applications do not require monad functionality but only those of applicative functors. Monads allow you to run actions depending on the outcomes of earlier actions.
do text <- getLine if null text then putStrLn "You refuse to enter something?" else putStrLn ("You entered " ++ text)
This is obviously necessary is some cases, but in other cases it is disadvantageous.
