本文介绍了iterate + forever = iterateM?用反馈重复一个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图永远重复一次IO操作,但将一次执行的结果提供给下一个。像这样:

   - 名字很差的
iterateM :: Monad m => (a - > m a) - > a - > mb
iterateM fa = fa>> = iterateM f

Hoogle似乎没有以帮助我,但我看到很多功能看起来非常接近我想要的,但没有一个看起来像是完全一样。

解决方案 div>

你是对的,我不知道这个特定类型的循环实现的地方。你的实现看起来很好;为什么不把它作为补丁提交给软件包?


I'm trying to repeat an IO action forever, but feeding the result of one execution into the next. Something like this:

-- poorly named
iterateM :: Monad m => (a -> m a) -> a -> m b
iterateM f a = f a >>= iterateM f

Hoogle didn't seem to help me, but I see plenty of functions which look enticingly close to what I want, but none seem to come together to be exactly it.

解决方案

You're right, I don't know of a place this particular kind of loop is implemented. Your implementation looks fine; why not submit it as a patch to the monad-loops package?

这篇关于iterate + forever = iterateM?用反馈重复一个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:49