0

Typeclassopedia's Chapter 5.3 notes:

Intuitively, it is this ability to use the output from previous computations to decide what computations to run next that makes Monad more powerful than Applicative.

This example demonstrates this intuition to me:

ghci> Just 100 >>= (\x -> if (x == 100) then Nothing else Just x) 
Nothing

I don't know (or expect that it's possible based on the above explanation) how to use (<*>) to achieve the same, above code.

Are there any other, more precise/strong examples that demonstrate the above text in Typeclassopedia?

Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
  • ...and see also [examples of data structures that are at each stage in the chain functor -> applicative -> monad](http://stackoverflow.com/q/7220436/791604). – Daniel Wagner Sep 17 '15 at 01:53

1 Answers1

4

Not really an example, but the exact property that you're looking for is that you can't write join :: Applicative f => f (f a) -> f a but you can write it if you change the constraint to Monad. In fact, if you just add this function to an applicative it immediately becomes as powerful as a Monad because with that you can define return = pure and m >>= f = join (fmap f m).

I can't remember on top of my head what the laws for join where, but it's mostly common sense stuff like join (return (return a)) == return a.

Cubic
  • 14,902
  • 5
  • 47
  • 92
  • 3
    Common sense stuff indeed: `join . return = id`, `join . fmap return = id` and `join . fmap join = join . join`. – duplode Sep 17 '15 at 02:06