All my favorite languages have a goto command. That is, you can create a label, and then later interrupt the flow of the program to go to the label. One of the more useful applications of this construct is to create an infinite loop, like this:
start:
goto start
Unfortunately, if I undertstand the compiler errors correctly, I can’t use this same syntax in F#. So, since it doesn’t seem to be supported natively, how can I implement the goto command in F#?
Surely, F# is a powerful enough language to implement a feature as simple as this. Other languages, such as Javascript, which do not natively support goto, are still able to implement it through a plug-in.
Further, I feel that F#, as one of the languages in the functional programming paradigm, should be able to support higher-level gotos: where you can pass gotos to gotos.
A label has a lot in common with a function: they both act as entry points to some code to be executed. Given that similarity, you can do the following:
One minor drawback is having to wrap all your code in closures. I don’t know–doesn’t seem too bad for getting something as handy as
goto.