[Haskell-cafe] [ZipList Monad] Final answer?

Etsuji Nakai enakai at redhat.com
Sat Oct 19 01:15:12 UTC 2013


>Violates the Monad laws, specifically join . join = join . fmap join:
>
>>>> let join x = bind x id
>>>> join (join [[[1]],[[],[2,3]]])
>[1,3]
>>>> join (fmap join [[[1]],[[],[2,3]]])
>[1]

That's right. Thanks. I found yet another pedagogical case:

f x = case x of
          1 -> MyZipList [1,0,0]
          2 -> MyZipList [0,2,0]
          3 -> MyZipList [0,0,3]
          otherwise -> MyZipList []

>MyZipList [1,2,3] >>= f >>= f
MyZipList [1,2,3]

>MyZipList [1,2,3] >>= \x -> (f x >>= f)
MyZipList [1]

So the conclusion is ZipList can never be a Monad in a strict sense, right?

- Etsuji


More information about the Haskell-Cafe mailing list