logoalt Hacker News

etermyesterday at 5:33 PM1 replyview on HN

C# is an interesting case because it shares a common runtime with F#, and F# guarantees TCO in most circumstances ( try / catch can stop it ) .

There is a "tail" prefix in the intermediate language (IL) bytecode that F# uses but Roslyn, the C# compiler, never emits.

So unlike F#, whether the same algorithm written in C# becomes a loop depends on JIT behaviour. This means if you're coming to a function cold in C# you can overflow the stack, while if you enter the same function fresh after it's been warmed up, it may have been optimised away by RyuJIT and if so you are able to call it safely for what would be large numbers of recursions.


Replies

pjmlpyesterday at 6:33 PM

The interesting case is the Common Language Runtime, not C#.

> More than 20 programming tools vendors offer some 26 programming languages — including C++, Perl, Python, Java, COBOL, RPG and Haskell — on .NET.

https://news.microsoft.com/source/2001/10/22/massive-industr...

MSIL thus had to support all of them.

Those differences between language semantics is why CLS was also a thing back then.

https://learn.microsoft.com/en-us/dotnet/standard/language-i...