F# vs C# – Why F# Has Interactive Mode but Not C#

%fcnettools

F# comes out of the box with an interactive REPL. C# has nothing of the sort and is in fact kinda difficult to play around without setting up a full project (though LINQpad works and its also possible to do via powershell).

Is there something fundamentally different about the languages that allows F# to have the interactive console but makes it difficult to implement it for C#?


Since many years later people are still coming to this question I should note that now there are many options. You can use powershell (pre-installed on every modern windows machine) to play with the .Net framework. Or you can use LINQpad to prototype arbitrary c# code. Or you can use ScriptCs or you can use an online jsfiddle-type environment like Complify.net or Jsil. Lots of options.

Best Answer

Is there something fundamentally different about the languages that allows F# to have the interactive console but makes it difficult to implement it for C#?

Yes.

F# is a descendant of the ML programming language, which in turn was heavily influenced by languages like Lisp and Scheme. Those languages were designed from day one to have three nice properties.

First, those languages do not really have statements the way you think of them in C#. Rather, almost everything is an expression that has a value, so an evaluate-and-then-print-the-value mechanism makes sense in almost every situation.

Second, those languages discourage programming with side effects, so you can make evaluations without worrying that you’re going to be messing up global state.

Third, most of the work you do in those languages is “at the top level”; there is typically no enclosing “class” or “namespace” or other context.

By contrast, C# emphasizes programming control flow with statements that produce side effects, and those statements are always in multiple nested containers -- a namespace, a class, a method, and so on.

So these are all things that make it harder for C# to have a REPL, but certainly not impossible. We’d just need to figure out what the semantics are for statements and expressions that appear outside of the usual context, and what the semantics are of mutations that change name bindings, and so on.

Why does F# have an interactive mode but not C#?

Because the F# team decided that having a REPL loop was a priority-one scenario for them. The C# team historically has not. Features do not get implemented unless they are the highest priority features that fit into the budget; until now, a C# REPL has not been at the top of our list.

The Roslyn project has a C# REPL (and will eventually have a VB REPL as well, but it is not ready yet.) You can download a preview release of it to see how you like it at

http://www.microsoft.com/en-us/download/details.aspx?id=27746