[Haskell-cafe] Applicative but not Monad

David Menendez dave at zednenem.com
Fri Oct 30 13:39:41 EDT 2009


On Fri, Oct 30, 2009 at 1:33 PM, Yusaku Hashimoto <nonowarn at gmail.com> wrote:
> Thanks for fast replies! Examples you gave explain why all
> Applicatives are not Monads to me.
>
> And I tried to rewrite Bob's Monad instance for ZipList with (>>=).
>
> import Control.Applicative
>
> instance Monad ZipList where
>  return = ZipList . return
>  (ZipList []) >>= _ = ZipList []
>  (ZipList (a:as)) >>= f = zlHead (f a) `zlCons` (ZipList as >>= f)

This is taking the first element of each list, but you need to take
the nth element. Try

  (ZipList (a:as)) >>= f = zlHead (f a) `zlCons` (ZipList as >>= zlTail . f)


-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list