Back
Close

A Babel of Languages on CodinGame

TBali
66.9K views

F#

F#

Checking the sample code

(Contributed by Djoums):

Looking at the syntax

  • This is very different from an imperative style code! A proper introduction to functional programming (FP) is unfortunately beyond the scope of this playground.
  • |> is the pipe forward operator, used to chain the function calls.
  • Comments are between (* and *). Don't ask...
  • There are some function names (Convert.ToString and PadLeft) which look exactly the same as in our C# solution. This is not a coincidence. As C#, F# and VB .NET are all targeting Microsoft's Common Language Infrastructure (CLI) on .NET Core, they share some of the standard libraries.
  • fun x -> defines anonymous functions on the fly.
  • if..then..else is not a conditional statement, but a conditional expression so it returns a result.

Other characteristics

F# defines itself as "functional-first" programming language. Unlike Haskell, which is pure, uncompromising FP, with F# you can mix in some imperative or object-oriented style in your code, when it makes sense. However, this can be abused. To demonstrate, I show an F# Chuck Norris solution in imperative style. Don't try this at home! :-)

Resources to check

Meme

Coming next...

The natural choice for the next section is the "most-FP language of all FP languages", Haskell...

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io