C# interoperability / how to call c# methods / f# as a non-dotnet developer

Hi, I don’t have a programming background (apart from a bit of scripting with Python and Javascript) and I don’t have any experience with dotnet. However, I’ve dabbled a bit with a couple of programming languages, and I find functional programming languages rather attractive. I’ve watched the videos to Grossman’s programming languages course on Coursera which uses SML. Now I wanted to try a functional language for small projects, and as I’m on Windows, F# sounds like a good fit. However, a lot of the material I’ve found seems to assume you already know dotnet. And, looking at the syntax, even something as simple as reading user input from the terminal seems to involve C#-isms. For me, this looks really weird inside the otherwise rather clean ML-style syntax.

I guess my actual questions are this:

  1. Does it make sense to use F# without any dotnet knowledge?
  2. How do you actually call and use C# libraries? Is there a nice summary somewhere that doesn’t assumes existing dotnet knowledge? (I’m mean, I understand that parentheses are used for method calls, the new keyword that I’ve seen a couple of times will probably instantiate a new instance of an object (right?), but I don’t really want to learn C# first.

I recommend you give it a try.
Of course there is stuff that you need to learn about dotnet (how the dotnet cli works, assemblies, project files, etc) in the same way as you have to learn how your IDE works.
But you don’t really need C#.
The .net class library is language independent and mostly works just fine with F#.
You just have to know that function calls into the library from F# typically look like calling a function with a single tuple as argument.
Example:

System.Console.Beep(400, 1000)
let s = System.Console.ReadLine()
printfn "%s" s

Instantiation of library classes is usually not different from instantiation of F# classes.

Thanks. But why is there no space between the function and the tuple?

The space is optional, as the parentheses delimit the argument and make it unambiguous for the compiler.
The style guide has specific recommendations on when and when not to add a space. Basically, when calling .net-style methods you omit the space (C# style) and for curry-able F# functions you keep them.

1 Like