What could be done as believed to be impossible in F# by Oskar Gewalli

June 11, 2020

In the presentation What could be done as believed to be impossible in F# by Oskar Gewalli, he discusses various advancements and capabilities in the F# programming language. He presents on the F# library F# Plus, which helps reduce boilerplate code and offers useful constructs for functional programming. Oskar emphasizes the importance of abstractions and forgetting differences to build software effectively, using examples like the Suave web framework and monad transformers. He also talks about the use of result types, computation expressions, and validation in F#, comparing it to other languages and libraries. The discussion covers the ergonomics of working with result types in F# and the benefits of computation expressions for handling side effects in a pure functional way. The speaker also touches on the evolution of F# and its use of computation expressions versus applicatives for modeling.

What could be done as believed to be impossible in F#: A comprehensive overview

Challenging the impossible with F# Plus

One of the core themes of Oskar Gewalli’s presentation was F# Plus, a library that has become a game-changer for reducing boilerplate and enabling more flexible and efficient coding in F#. This library includes generic operators and constructs that reduce the infrastructure required for private projects and proofs of concept. It introduces tools like monad transformers and generic lenses, which allow programmers to handle nested immutable data and transform monads — both previously believed impossible in F#.

Oskar explained that monad transformers simplify complex, layered computations, while generic lenses provide easy access to deep parts of immutable data structures without writing extensive boilerplate. By making these abstractions available in F#, F# Plus significantly enhances the language’s functional capabilities.

 

Abstractions and type classes

Oskar emphasized the importance of abstraction in functional programming, particularly in F#, where simplifying differences helps streamline software development. One of the key patterns discussed was the pipe operator, which F# uses to allow operations on various types. However, through the F# Plus library, type classes can be emulated in F#, enabling developers to use more advanced operations on types that implement certain classes. This can be done with statically resolved type parameters, pushing the boundaries of F# beyond its default limitations.

This shift allows developers to perform operations on a wider range of data types, demonstrating the powerful, flexible abstractions that F# can offer when enhanced with the right tools.

 

Enhanced validation and error handling

The contrast between regular F# and F# Plus is evident in how they handle validation. Regular F# validation typically relies on attributes, limiting the depth and diversity of error types. With F# Plus, however, validations become more content-rich, allowing for more expressive error types beyond just strings. This added versatility allows developers to fine-tune their error-handling strategies to suit the specific needs of their projects.

Oskar highlighted that strictly typed error handling in F# gives developers more control over failure cases compared to default generic error messages. Although exceptions can still be used, F# encourages avoiding exceptions for control flow, instead favoring Algebraic Data Types (ADTs) or result types for error handling.

 

Computation expressions and monad transformers

Oskar dove into the powerful concept of computation expressions in F#, which allow developers to combine functions that return result types in a more functional manner. While regular F# does not provide extensive helper functions for working with result types, F# Plus adds utilities that make working with these types easier and more consistent.

The presentation also touched on monad transformers like Option T in F#, which allow developers to build nested computations, such as combining async operations with optional values. Although computation expressions can look imperative, they are a robust way to handle side effects in a functional paradigm.

 

F#’s community and ongoing evolution

Oskar’s talk highlighted the ongoing debate within the functional programming community about complex abstractions. While some developers lean toward keeping things simple for the sake of newcomers, others see value in embracing powerful abstractions like those in F# Plus. This tension reflects broader discussions in languages like Haskell, where there’s always a balance between simplicity and power.

Another significant takeaway from Oskar’s talk is that many F# developers utilize it as a “better C#” with a few functional concepts, while others dive deep into more advanced features like higher-order types and type classes. Despite F#’s type system limitations, Oskar believes the language’s flexibility continues to push the boundaries of what’s possible.

 

Conclusion

Oskar Gewalli’s presentation provided a comprehensive overview of how F# developers can break through perceived limitations using libraries like F# Plus and advanced concepts like monad transformers, computation expressions, and type classes. What was once thought impossible in F# has now become reality, thanks to the growing set of tools and abstractions available to the community.

For developers curious about maximizing F#’s potential, Oskar’s insights serve as a reminder that the boundaries of the language are continually being redefined. As more programmers explore the capabilities of F# and its libraries, what seems impossible today may well be achievable tomorrow.

 

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.