tail-call-optimization

What is the current state of tail-call-optimization for F# on Mono (2.11)?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 05:07:43
What is the current state of Tail Call Optimization (TCO) implementation on Mono (2.11) ? Read somewhere that all the codebase would need to be modified to use a callee-pops-arguments convention. What is the status of this change ? Is the ARM/Linux port up to date on this matter ? Thanks! Tail calls definitely work on mono on linux - tested using let rec f a = f (a+1) which didn't crash - tested on Mono 2.10.2 UPDATE Tested with link from Brian - https://bugzilla.novell.com/show_bug.cgi?id=476785 which crashes on Mono 2.10.2 despite generating .tail instructions 来源: https://stackoverflow.com

Why do no javascript engines support tail call optimization?

烈酒焚心 提交于 2019-12-04 03:58:39
问题 I recently learned about tail call optimization in Haskell. I've learned from the following posts that this is not a feature of javascript: Tail Recursion optimization for JavaScript? Are any Javascript engines tail call optimized? Is there something inherent to javascript's design that makes tail call optimization especially difficult? Why is this a main feature of a language like haskell, but is only now being discussed as a feature of certain javascript engines? 回答1: Tail call optimisation

vs2010 c++ tail call optimization

时光怂恿深爱的人放手 提交于 2019-12-04 03:05:13
Consider the following code: int fac_aux( int x, int res ) { if( x == 1 ) return res; else return fac_aux( x - 1, res * x ); } int fac( int x ) { return fac_aux( x, 1 ); } int main() { int x = fac( 50 ); std::cout << x; return 0; } According to generated asm file everything is ok, tail call is optimized. Try to replace int x = fac( 50 ); with int x = fac_aux( 50, 1 ); Strange enough, but tail call optimization is disappeared. As far as I remember there was no such a strange compiler behaviour in VS2008. Any ideas why these things happen and how to be sure of tail call optimization is done? ;

Why is this F# sequence function not tail recursive?

家住魔仙堡 提交于 2019-12-03 18:00:04
问题 Disclosure: this came up in FsCheck, an F# random testing framework I maintain. I have a solution, but I do not like it. Moreover, I do not understand the problem - it was merely circumvented. A fairly standard implementation of (monadic, if we're going to use big words) sequence is: let sequence l = let k m m' = gen { let! x = m let! xs = m' return (x::xs) } List.foldBack k l (gen { return [] }) Where gen can be replaced by a computation builder of choice. Unfortunately, that implementation

Tail recursion with Groovy

谁说我不能喝 提交于 2019-12-03 16:05:30
I coded 3 factorial algorithms: First, I expect to fail by Stack Overflow. No problem. Second, I try tail recusive call , convert previous algorithm from recursive to iterative. It doesn't work but I don't understand why . Third, I use trampoline() method and works fine as I expect. def factorial factorial = { BigInteger n -> if (n == 1) return 1 n * factorial(n - 1) } factorial(1000) // Stack Overflow factorial = { Integer n, BigInteger acc = 1 -> if (n == 1) return acc factorial(n - 1, n * acc) } factorial(1000) // Stack Overflow, why??? factorial = { Integer n, BigInteger acc = 1 -> if (n =

Is my rewritten foldl function optimised?

旧城冷巷雨未停 提交于 2019-12-03 07:19:01
I just started Haskell 2 days ago so I'm not yet sure about how to optimise my code. As an exercise, I have rewritten foldl and foldr ( I will give foldl here but foldr is the same, replacing last with head and init with tail ). The code is: module Main where myFoldl :: ( a -> ( b -> a ) ) -> a -> ( [b] -> a ) myFoldl func = ( \x -> (\theList -> if (length theList == 0) then x else myFoldl func (func x (last theList) ) (init theList) ) ) My only concern is that I suspect Haskell can't apply tail call optimisation here because the recursive call is not made at the end of the function. How can I

Explain to me what the big deal with tail call optimization is and why Python needs it

人走茶凉 提交于 2019-12-03 04:48:12
So apparently, there's been a big brouhaha over whether or not Python needs tail call optimization. This came to a head when someone shipped Guido a copy of SICP because he didn't "get it." I'm in the same boat as Guido. I understand the concept of tail call optimization. I just can't think of any reason why Python really needs it. To make this easier for me to understand, could someone give me a snippet of code that would be greatly simplified using TCO? Personally, i put great value on tail call optimization; but mainly because it makes recursion as efficient as iteration (or makes iteration

Can an F# function be considered tail recursive it uses the TailCall .net opcode

做~自己de王妃 提交于 2019-12-01 18:26:41
Since .net has the TailCall opcode, can this be used to deterime if an F# function is truly tail recursive? If it is true, has anyone made a VS add-in that identifies tail and non-tail functions? See this blog post on the F# team blog for a summary of how F# compiles tail calls. In short, Direct recursive tail calls are typically converted into loops. Mutual recursion and indirect non-recursive tail calls are typically turned into .NET tail calls. but see the full post for all of the gory details. Yes, if the compiler emits the tail call instruction, that call will be tail recursive (as of CLR

Does Java support tail recursion? [duplicate]

前提是你 提交于 2019-12-01 02:21:27
Possible Duplicate: Why does the JVM still not support tail-call optimization? I see so many different answers online, so I thought I'd ask the experts. There is difference between tail recursion and tail recursion optimization. Tail recursion is supported by java because there is nothing special in it, tail recursion optimization is not supported. 来源: https://stackoverflow.com/questions/4401052/does-java-support-tail-recursion

Does Java support tail recursion? [duplicate]

╄→гoц情女王★ 提交于 2019-11-30 21:53:16
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why does the JVM still not support tail-call optimization? I see so many different answers online, so I thought I'd ask the experts. 回答1: There is difference between tail recursion and tail recursion optimization. Tail recursion is supported by java because there is nothing special in it, tail recursion optimization is not supported. 来源: https://stackoverflow.com/questions/4401052/does-java-support-tail