[Haskell-cafe] Stacking monads

Andrew Coppin andrewcoppin at btinternet.com
Fri Oct 3 15:14:22 EDT 2008


Jake McArthur wrote:
> Andrew Coppin wrote:
>> (As an aside, Control.Monad.ap is not a function I've ever heard of. 
>> It seems simple enough, but what an unfortunate name...!) 
> I think it makes sense. It stands for "apply," or at least that is 
> what I think of when I see it.

There can be little doubt that this is what the designers intended. 
However, why didn't they name it, say, "apply"? I just think that 
Haskell already has too many names like "id" and "nub" and "elem" and 
"Eq" and "Ix". Would it kill anybody to write out more descriptive names?

Also, I'm fuzzy on why ap is even a useful function to have in the first 
place. I can see what it does, but when are you ever going to need a 
function like that? (I'm not saying we should get rid of it, I'm just 
puzzled as to why anybody thought to include it to start with.)

> If we have a function f :: A -> B -> C -> D and values a :: m A, b :: 
> m B, c :: m C, then we can do:
>
>    f `liftM` a `ap` b `ap` c
>
> ... which is the same as (using Applicative):
>
>    f <$> a <*> b <*> c
>
> ... both having type m D.

Again we seem to have two different sets of functions which none the 
less appear to do exactly the same thing.



More information about the Haskell-Cafe mailing list