Expert F#中的代码如下:
// Perform a CPU-intensive operation on the image.
pixels |> Func.repeatN processImageRepeats (Array.map (fun b -> b + 1uy))
Func.repeatN有什么用? 它似乎已经消失了。是否有一个替换Func.repeatN的函数?
了解更多信息: 我在谷歌搜索它,有一个出现在顶部但我无法访问此网站(我的关键字是:Func.RepeatN): F#2008年9月社区技术预览,1.9.6.2 stuff.mit.edu/afs/athena.mit.edu/.../README-fsharp.html - Permutation模块保留在PowerPack中; Func。*,例如Func.repeatN已删除; CompatArray和CompatMatrix模块已删除。 ...
答案 0 :(得分:1)
这绝对不是标准的F#库函数。
除非这是一些性能章节(作者为了演示目的只需要较慢的实现),该函数应该很可能重复对输入应用指定的转换,然后对前一个应用程序的结果应用。当它达到零时,它将返回原始输入未修改。
实现是一个简单的递归函数:
module Func =
let rec repeatN count f input =
// Repeating less than zero times - return the input
if count <= 0 then input
// Otherwise apply the function once and repeat (count - 1) times
else repeatN (count - 1) f (f input)
编辑我原来的想法(现已删除)可能是错的(我没有书来检查),所以这是一个改进的答案。