Functions are just an instance of arrows, he asks: "Why use monads instead of just Maybe ."
All that you can do with the arrows, of course, can be done using functions, since an Arrow (->) instance can talk about only one small part of the functions, namely, that in a class like Arrow . However, arrows have more instances than just simple functions, so we can use ssame functions to work with more complex types.
The arrows are good, because they can have much more structure than just a function, when going around only with fmap we have no way to accumulate effects, more expressive than monads! Consider the Claysley arrow,
newtype Kleisli mab = Kleisli {runKleisli :: a -> mb}
This forms an arrow when m is a monad. Thus, each Monad forms an arrow, and therefore we can create monadic calculations by smoothly composing a -> mb and do all kinds of useful things like this. Some XML libraries use arrows to abstract over functions from an element to its subitems and use this to move around a document. Other parsers use arrows (their original purpose), although currently this seems to drop out due to Applicative rejection.
What you hopefully noticed is that arrows are more general, when we just talk about arrows, we avoid duplicating all the code we need to write in order to do something with our analyzers, xml scrapers and monadic functions
Just like choosing Monad over Maybe , we lose some power, since we can no longer create specific instructions, but we return a more general code.
source share