我已经在F#中编写了一个有趣的函数,它可以遍历和映射任何数据结构(非常类似于Haskell的Scrap Your Boilerplate中的everywhere函数)。不幸的是,即使是相当小的数据结构,它也很快导致堆栈溢出。我想知道如何将它转换为尾递归版本,延续传递样式版本或命令式等效算法。我相信F#支持monad,所以延续monad是一个选项。 // These are used for a 5
我不知道怎么描述准确,看到代码,请 def callForever(f: Future[Int]): Unit = {
f.onComplete {
case Failure(e) =>
//do something
case Success(c) =>
// do again
val nextConn: Future[Int] =
这是我的任务。 (http://prnt.sc/aa3gwd) 我一直工作在这其中一个导师,这是我们想出了这么远。这 fun mult(a,b) =
let
val product = 0
in
if (a = 0) then
0
else
while a > 0 do
(
product := product +
在阅读Guido's reasoning for not adding tail recursion elimination to Python,我炮制在Haskell几乎尾递归的这个例子: triangle :: Int -> Int
triangle 0 = 0
triangle x = x + triangle (x - 1)
这当然不是一个尾调用,因为虽然递归呼叫本身处于“返回”状