diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-09-07 21:25:54 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-09-07 21:25:54 -0700 |
commit | 45a7da1426586e9fe2abe19b41a296e76ef1d78a (patch) | |
tree | e981446eb8e2ccabb2cae315972e773802a3664d /test/files | |
parent | c55e32d71d6c74c9280fb19c336969412c9857ec (diff) | |
parent | 4ddff662995a0abaf5b1eb872c1233b60e9eb3c0 (diff) | |
download | scala-45a7da1426586e9fe2abe19b41a296e76ef1d78a.tar.gz scala-45a7da1426586e9fe2abe19b41a296e76ef1d78a.tar.bz2 scala-45a7da1426586e9fe2abe19b41a296e76ef1d78a.zip |
Merge pull request #2865 from folone/trampolines
Alter TailRec to have map and flatMap
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/tailcalls.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index 1d4124e138..e5d8891cc7 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -391,7 +391,20 @@ object Test { def isOdd(xs: List[Int]): TailRec[Boolean] = if (xs.isEmpty) done(false) else tailcall(isEven(xs.tail)) + def fib(n: Int): TailRec[Int] = + if (n < 2) done(n) else for { + x <- tailcall(fib(n - 1)) + y <- tailcall(fib(n - 2)) + } yield (x + y) + + def rec(n: Int): TailRec[Int] = + if (n == 1) done(n) else for { + x <- tailcall(rec(n - 1)) + } yield x + assert(isEven((1 to 100000).toList).result) + //assert(fib(40).result == 102334155) // Commented out, as it takes a long time + assert(rec(100000).result == 1) } |