F# Down Under by Sashan Govender

September 10, 2024

In the F# Down Under by Sashan Govender presentation, he shares his experience and enthusiasm for using the Microsoft-based programming language F#. He discusses how F# stands out from other languages like C++, C, Python, and bash due to its ability to blend a pragmatic approach with expressiveness and integration with the vast net ecosystem. Sashan also highlights F#’s benefits for concurrent programming, asynchronous workflows, and handling unstructured data using type providers. He reflects on the challenges of learning functional programming languages and shares his personal journey of learning and re-learning F#. Despite some initial hurdles, Sashan emphasizes the importance of choosing a language that one enjoys working with and the rewards of adapting to new programming paradigms.

F# Down Under: A comprehensive overview

Discovering F#: A language with sibling ties

Sashan Govender kicked off his talk by clarifying a common misconception – F# is not “F hashtag” but rather a Microsoft-based language developed by Don Syme. As a “sibling” to C#, F# integrates well with the .NET ecosystem, providing a unique balance between functional programming principles and the power of type inference, scripting, and domain-driven design. What makes F# stand out for Sashan is its blend of expressiveness and practicality, allowing developers to achieve logical correctness and robust runtime behavior with ease.

 

The F# advantage in asynchronous and concurrent programming

One of the standout features of F# is its elegant handling of asynchronous and concurrent programming. Sashan highlighted how he first discovered F# around 2010, intrigued by its async programming model. Unlike languages like C++ or Java, which rely heavily on state management and thread control, F# abstracts away the complexity using async computation expressions. This approach allows developers to write code that looks simple, similar to await statements in C#, but behind the scenes, it manages threads and bind calls efficiently.

Sashan emphasized how F# frees up system threads while awaiting responses, allowing the flow of control to continue without blocking the system. This makes asynchronous programming far more approachable, solving many of the issues that traditional languages face, such as thread management and inversion of control. However, he also cautioned against certain pitfalls, like using sequence expressions within loops, which can cause compiler errors due to shadowing definitions.

 

Async sequences and task expressions: Taking F# further

Sashan went on to explain two ways to handle asynchronous computations in F#. First, developers can execute tasks in parallel using async computations. Secondly, they can utilize async sequences, a feature that can be downloaded from NuGet and allows full for-loops similar to async computations. He also mentioned task expressions, which were added to improve F#’s compatibility with the .NET layer that predominantly uses tasks.

While F# has supported async programming since 2007, Sashan reflected on how most mainstream languages lagged behind in adopting these practices. This early support positioned F# as a language that pushed the boundaries of concurrent programming, making it ideal for modern applications where scalability and performance are critical.

 

Type providers: A game-changer for unstructured data

A notable section of the talk focused on type providers, a feature that saved Sashan weeks of work on a project involving unstructured XML data. Type providers infer schemas and generate types automatically, simplifying the process of working with complex or unstructured data sources like XML and third-party APIs. Sashan demonstrated how F#’s type providers could easily transform an XML document into structured types, drastically reducing the manual effort involved in such tasks.

He also praised F#’s scriptability, allowing developers to write and test code directly in the interpreter. This feature, combined with the powerful capabilities of type providers, positions F# as a top choice for developers who work with data-intensive applications and require quick iteration cycles.

 

Domain-driven design in F#

Sashan’s enthusiasm for F# was evident as he discussed its strength in domain-driven design (DDD). F#’s lack of excessive syntax makes it particularly friendly for modeling business domains, and the use of discriminated unions and records helps describe multiple possibilities for values. This clarity makes it easier for business stakeholders to understand the models, enhancing collaboration between developers and non-technical stakeholders.

However, he acknowledged that working with REST interfaces can be challenging in F# due to the limitations of discriminated unions. His solution? Flattening them when necessary. Alternatively, Sashan suggested using gRPC, which offers better compatibility with F# domain types, thanks to its support for optional and one-off types.

 

Challenges of learning Functional Programming

One of the key hurdles to wider adoption of F#, according to Sashan, is the steep learning curve associated with functional programming. Many developers, especially those coming from object-oriented backgrounds, struggle with concepts like immutability, recursion, and high-order functions. The unfamiliarity of these concepts often leads to frustration and abandonment, despite the clear advantages F# provides in terms of concurrency and correctness.

He also touched on the pain of unlearning old habits, a common challenge when transitioning from languages like C++ to functional programming. Despite these challenges, Sashan encouraged developers to stick with it, as the long-term benefits far outweigh the initial learning curve.

 

Re-learning F# with .NET Core

Sashan wrapped up his talk by sharing his personal journey of re-learning F#. After initially learning OCaml, he revisited F# five years ago when .NET Core was released. With prior experience, picking up F# again was easier, but the biggest challenge was shifting his mindset away from traditional paradigms. This re-learning experience, he said, is what makes F# so exciting — it challenges developers to think differently, pushing the boundaries of what’s possible in software development.

 

Conclusion: The future of F# down under

Sashan Govender’s talk painted a picture of F# as a powerful, yet underutilized language with immense potential. From its early adoption of async programming to its unique type providers and strong domain-driven design capabilities, F# is a language that offers both expressiveness and pragmatism.

While the learning curve may be steep, developers willing to embrace functional programming’s new paradigms will find F# to be a rewarding language. As Sashan continues to advocate for F# in Australia, there’s hope that more developers will join the journey and discover the benefits of this powerful functional-first language.

 

Additional resources

Check out more from the MeetUp Func Prog Sweden. Func Prog Sweden is the community for anyone interested in functional programming. At the MeetUps the community explore different functional languages like Erlang, Elixir, Haskell, Scala, Clojure, OCaml, F# and more.