
Thank you for your correction. I tried your (>>=) and replaced
return's definition with
return = ZipList . repeat
then as you said this works fine for infinite lists.
Cheers,
-~nwn
On Sat, Oct 31, 2009 at 2:39 AM, David Menendez
On Fri, Oct 30, 2009 at 1:33 PM, Yusaku Hashimoto
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
http://www.eyrie.org/~zednenem/