If you re a seasoned .NET library author, there is a good chance that you ve had to write some component that is acting on arbitrary user-defined types. This includes serializers, structured loggers, mappers, deep cloners, validators, parsers, random value generators, equality comparers, and many more. Such components typically focus on the data exposed by user types Continue reading Source…
Programming with algebraic effects and handlers, a method for reasoning about computational effects of programs that originates from functional programming research, has recently found increasing adoption in more mainstream languages. Implementations can be found in OCaml, Haskell, Scala, F# and the Koka language. Algebraic effects are an immensely powerful language feature that can be used…
A few years back, I blogged about how one could use the TypeShape library for writing practical generic programs in F#. While the library has seen success in both OSS and proprietary applications, from the beginning there have existed pretty self-evident usability issues when working with the library itself. On simple inspection of a basic Continue reading Applying the Tagless-Final pattern in F#…
At Jet we do a lot of event sourcing. Our event types are typically modelled using discriminated unions: Since DUs carry no canonical representation in most popular serialization formats, encoding and decoding typically involves a bit of manual work: where the functions serialize : 'T - string and deserialize : string - 'T represent some Continue reading A Contract Pattern for Schemaless…
One of the interesting challenges when dealing with generic programming is testing. How could you possibly achieve extensive test coverage for a piece of code that works with arbitrary types? Suppose for instance that we have implemented a generic equality function: One of the properties we would expect this function to satisfy is reflexivity. Put Continue reading Property Testing Generic Programs
During a recent conversation with a group of F# developers, I started making the case for recursion and its importance in day-to-day programming. My peers reacted with surprise to this opinion of mine, responding that they thought that recursion is an inherently inefficient way of defining programs. We are taught this rule when studying procedural Continue reading On the Significance of Recursion
Point-free programming (or point-less programming, for the more cynically inclined) is a paradigm that advocates the formulation of programs by means of function composition. In the point-free style programs avoid explicitly nominating function arguments (or points ), deriving instead complex function definitions by means of applying higher-order combinators on simpler functions. To give an F#…
F# is a functional-first programming language that comes with a substantial object-oriented feature set. It is so feature-complete in fact, that almost any C# class can be ported over to F# code with little substantial alteration. However significant, this subset of the language is seeing limited appreciation from the community, which I suspect is partly Continue reading Why OO Matters (in F#)
Purely functional programming according to wikipedia designates a programming paradigm that treats all computation as the evaluation of mathematical functions. Purely functional programing may also be defined by forbidding changing state and mutable data. The importance of the purely functional approach cannot be overstated: it eliminates entire classes of mutation-related bugs; encourages…
Exception handling is an error management paradigm that has often been met with criticism. Such criticisms typically revolve around scoping considerations, exceptions-as-control-flow abuse or even the assertion that exceptions are really just a type safe version of goto. To an extent, these seem like valid concerns but it is not within the scope of this Continue reading You re better off using…