[Haskell-cafe] A challenge
Claus Reinke
claus.reinke at talk21.com
Wed Apr 8 12:21:49 EDT 2009
|iterateM 0 _ _ = return []
|iterateM n f i = (i:) <$> (iterateM (n-1) f =<< f i)
|iterateM' n f i = sequence . scanl (>>=) (return i) $ replicate n f
These function are not the same (sequence of scanl? try using print
in f). Also, I seriously hope you are not looking for this line noise:-)
iterateM' = (foldr op (const $ return []) .) . replicate
where f `op` x = uncurry (<$>) . ((:) &&& ((x =<<) . f))
Because if you do, your penance for using it would involve
demonstrating that this is equivalent (+-1), or not (and do not
mention my name anywhere near it!-)
Claus
More information about the Haskell-Cafe
mailing list