There are a lot of functions that accomplish the same thing, but using Applicative
vs Monad
definitions.
Some examples are:
(<*>)
vsap
pure
vsreturn
(*>)
vs(>>)
traverse
vsmapM
sequenceA
vssequence
liftA
vsliftM
liftA2
vsliftM2
- etc.
And for Alternative
vs MonadPlus
:
empty
vsmzero
(<|>)
vsmplus
In the scenario that prompted this question, I wanted to traverse
/mapM
where the Applicative
/Monad
is []
.
In general, when it is known that the result will be the same, is it better style to use the Applicative
ones or the Monad
ones? E.g., is one more readable than another, or maybe faster than the other?
Edit (in response being suggested as a duplicate): Personally, I find these to be equally readable. I am in no way asking about maintainability, as these can be used interchangeably, and preferring one over another would have no impact on the code structure. I'm really wondering if one is more idiomatic, or more efficient, than the other.