This is the second post in a series on designing software for weavers. These posts contain random thoughts and musings based on design challenges that I come across as I build a real-world project. In the first post I give the context for this project and presented the code for a initial domain-driven design. In this post and the next one, we’ll move to the next stage, converting between a…
This post is part of the 2025 F# Advent Calendar. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. Recently, I have taken up a new hobby, hand weaving. As a meditative, physical activity with tangible results, it’s a great antidote to doom-scrolling and spending too much time in front of a screen. The first time I tried it, something about…
In the first post in this series, we came up with some properties that could be used to test a run-length encoding implementation: The output must contain all the characters from the input, in the same order Two adjacent characters in the output cannot be the same The sum of the run lengths in the output must equal the total length of the input If the input is reversed, the output must also be…
In the previous post we attempted to define some properties for a run-length encoding (RLE) implementation, but got stuck because the random values being generated by FsCheck were not very useful. In this post we’ll look at a couple of ways of generating “interesting” inputs, and how to observe them so that we can be sure that they are indeed interesting. Observing the generated…
This series of posts is a follow-up to my previous series on property-based testing and the Enterprise Developer From Hell. It revisits the fundamentals of property-based testing and how to use the EDFH to help design useful and effective tests.
In a previous series of posts, I introduced you to the burned-out and lazy programmer known as the Enterprise Developer From Hell, or the EDFH for short. As we saw, the EDFH loves to practice malicious compliance. Recently, the EDFH’s influence was apparent with this viral answer to an interview problem. Write a function that converts the input to the output. Input: “aaaabbbcca”…
These terms and conditions form your agreement with this site (hereafter, the SITE) and ScottW (hereafter, ME). By reading this site, you agree to the following: You acknowledge that this SITE is written by one person, ME, over many years as I was learning, and that many of the posts may be out-of-date, incomplete, or just plain wrong. You also acknowledge that the ME of today is not happy with…
In this series, we looked at six different approaches to dependency injection. In the first post, we looked at “dependency retention” (inlining the dependencies) and “dependency rejection”, or keeping I/O at the edges of your implementation. In the second post, we looked at injecting dependencies using standard function parameters. In the third post, we looked at dependency…
In this series, we are looking at six different approaches to dependency injection. In the first post, we looked at “dependency retention” (inlining the dependencies) and “dependency rejection” (keeping I/O at the edges of your implementation). In the second post, we looked at injecting dependencies using standard function parameters. In the third post, we looked at…
In this series, we are looking at six different approaches to dependency injection. In the first post, we looked at “dependency retention” (inlining the dependencies) and “dependency rejection” (keeping I/O at the edges of your implementation). In the second post, we looked at injecting dependencies as standard function parameters. In this post, we’ll look at…
In this series, we are looking at six different approaches to dependency injection. In the first post, we looked at “dependency retention” (inlining the dependencies) and “dependency rejection” (keeping I/O at the edges of your implementation). In this post, we’ll look at “dependency parameterization” as a way of managing dependencies. Dependency…
This post is part of the 2020 F# Advent Calendar. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. In this series of posts, we’ll look at six different approaches to doing “dependency injection”. This post was inspired by Mark Seemann’s similar series of posts, and covers the same ideas in a slightly different way. There are…
So you’re all excited about functional programming, and you’ve been learning F# in your spare time, and you’re annoying your co-workers by ranting about how great it is, and you’re itching to use it for serious stuff at work… But then you hit a brick wall. Your workplace has a “C# only” policy and won’t let you use F#. If you work in a typical…
In this series, we’ll look at recursive types and how to use them, and on the way, we’ll look at catamorphisms, tail recursion, the difference between left and right folds, and more.
One comment I hear often is a complaint about the gap between theory and practice in F# and functional programming in general. In other words, you know the theory, but how do you actually design and implement an application using FP principles? So I thought it might be useful to show you how I personally would go about designing and implementing some little applications from beginning to end.…
In this series, you’ll learn what computation expressions are, some common patterns, and how to make your own. In the process, we’ll also look at continuations, the bind function, wrapper types, and more.
One of the most common complaints about F# is that it requires code to be in dependency order. That is, you cannot use forward references to code that hasn’t been seen by the compiler yet. In this series, I discuss dependency cycles, why they are bad, and how to get rid of them.
In this series, we’ll look at some of the ways we can use types as part of the design process. In particular, the thoughtful use of types can make a design more transparent and improve correctness at the same time. This series will be focused on the “micro level” of design. That is, working at the lowest level of individual types and functions. Higher level design approaches, and…
In this series of posts we’ll look at how functions and values are combined into expressions, and the different kinds of expressions that are available in F#.
In this series of posts, I’ll look at how you might handle the common security challenge of authorization. That is, how can you ensure that clients of your code can only do what you want them to do? This series will sketch out two different approaches, first using an approach called capability based security, and second using statically checked types to emulate access tokens. Interestingly,…
In this series of posts, I’ll look at how you can thread state through a series of pure functions in a convenient way. To start with, I’ll tell the story of Dr Frankenfunctor and the Monadster, and how the Doctor needed a way to create “recipes” that were activated when lightning struck. The Doctor then devised ways to work with these recipes using functions such as map,…
As has been stressed many times before, F# is fundamentally a functional language at heart, yet the OO features have been nicely integrated and do not have a “tacked-on” feeling. As a result, it is quite viable to use F# just as an OO language, as an alternative to C#, say. In this series, we’ll look at how F# supports object-oriented classes and methods.
Do you want to port C# code to F#? In this series of posts we’ll look at various approaches to this, and the design decisions and trade-offs involved.
This series of posts will introduce you to the fundamentals of property-based testing: how it is different from traditional example-based testing, why it is important, and how to work with properties in theory and practice. A follow-up series is available too: The Return of the Enterprise Developer From Hell. There is also a talk on property-based testing based on these posts. Slides and video…
“I think I understand functional programming at the micro level, and I have written toy programs, but how do I actually go about writing a complete application, with real data, real error handling, and so on?" This is a very common question, so I thought that in this series of posts I’d describe a recipe for doing exactly this, covering design, validation, error handling, persistence,…
This series of posts will introduce you to the fundamentals of functional programming – what does it really mean to “program functionally”, and how this approach differs from object oriented or imperative programming.
F# is not just about functions; the powerful type system is another key ingredient. And just as with functions, understanding the type system is critical to being fluent and comfortable in the language. In addition to the common .NET types. F# has some other types that are very common in functional languages but not available in imperative languages like C# or Java. This series introduces these…
In this series, we’ll look at a very common “pattern” known as a monoid. Monoids are not really a design pattern; more an approach to working with many different types of values in a common way. In fact, once you understand monoids, you will start seeing them everywhere!
This series of posts will give you a guided tour through the main features of F# and then show you ways that F# can help you in your day-to-day development.
In this series of posts, I’ll attempt to describe some of the core functions for dealing with generic data types (such as Option and List). This is a follow-up post to my talk on functional patterns. Yes, I know that I promised not to do this kind of thing, but for this post I thought I’d take a different approach from most people. Rather than talking about abstractions such as type…
In this series, we’ll look at how so-called “applicative parsers” work. In order to understand something, there’s nothing like building it for yourself, and so we’ll create a basic parser library from scratch, then some useful “parser combinators”, and then finish off by building a complete JSON parser.
This post is part of the 2019 F# Advent Calendar. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. Six and half years ago, I wrote a post and did a talk on what I called “Railway Oriented Programming”. It was a way for me to explain to myself and others how to use Result/Either to for chaining together error-generating functions.
This post is part of the 2018 F# Advent Calendar. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. “Why F# is the best enterprise language” is not meant to be a clickbait title – it is my sincere opinion, and in this post I will attempt to justify it. If you stick around to the end, I hope that you will agree, or at least be a…
This post is part of the F# Advent Calendar in English 2017 project. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. In most discussions of functional design principles, we focus on implementing business workflows as pure functions with inputs and outputs. But where do these inputs come from? And where do the outputs go? They come from, or go to,…
This post is part of the F# Advent Calendar in English 2016 project. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. UPDATE: This post is superceded by a newer one here. For people who are learning functional programming techniques, one of the more common questions is: “how do you do dependency injection?” This series of posts…
Last year, I wrote a post called “Happy F# Day”, explaining why I thought F# needed a “birthday” that we could celebrate as a community. Here we are one year later! I’m going to promote that date (April 12th) again, and use it an excuse to review what has happened in the last year in the world of F#. And a lot has happened in the last year. Here’s my personal…
UPDATE: Slides and video from my talk on this topic In this, the third part of my two-part mega-post, I’m continuing to stretch the simple turtle graphics model to the breaking point. In the first and second post, I described thirteen different ways of looking at a turtle graphics implementation. Unfortunately, after I published them, I realized that there were some other ways that I had…
UPDATE: Slides and video from my talk on this topic This post is part of the F# Advent Calendar in English 2015 project. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. In this two-part mega-post, I’m stretching the simple turtle graphics model to the limit while demonstrating partial application, validation, the concept of…
UPDATE: Slides and video from my talk on this topic This post is part of the F# Advent Calendar in English 2015 project. Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this. I was discussing how to implement a simple turtle graphics system some time ago, and it struck me that, because the turtle requirements are so simple and so well known, it would…
UPDATE: Slides and video from my talk on this topic In this series, we are looking at how applicative parsers and parser combinators work. In the first post, we created the foundations of a parsing library. In the second post, we built out the library with many other useful combinators. In the third post, we improved the error messages. In this last post, we’ll use the library we’ve…
UPDATE: Slides and video from my talk on this topic In this series, we are looking at how applicative parsers and parser combinators work. In the first post, we created the foundations of a parsing library. In the second post, we built out the library with many other useful combinators. In this post, we’ll rework the library to provide more helpful error messages. 1. Labelling a Parser In…
UPDATE: Slides and video from my talk on this topic In this series, we are looking at how applicative parsers and parser combinators work. In the first post, we created the foundations of a parsing library. In this post, we’ll build out the library with many other useful combinators. The combinator names will be copied from those used by FParsec, so that you can easily migrate to it. 1.
UPDATE: Slides and video from my talk on this topic In this series, we’ll look at how so-called “applicative parsers” work. In order to understand something, there’s nothing like building it for yourself, and so we’ll create a basic parser library from scratch, and then some useful “parser combinators”, and then finish off by building a complete JSON…
This post is the sixth in a series. In the previous post, we briefly looked at some generic types. In this post, we’ll do some deeper dives into some real-world examples of using trees and folds. Series contents Here’s the contents of this series: Part 1: Introduction to recursive types and catamorphisms A simple recursive type Parameterize all the things Introducing catamorphisms…
This post is the fifth in a series. In the previous post, we spent some time understanding folds for specific domain types. In this post, we’ll broaden our horizons and look at how to use generic recursive types. Series contents Here’s the contents of this series: Part 1: Introduction to recursive types and catamorphisms A simple recursive type Parameterize all the things Introducing…
This post is the fourth in a series. In the previous post, I introduced “folds”, a way of creating top-down iterative functions for recursive types. In this post, we’ll spend some time understanding folds in more detail. Series contents Here’s the contents of this series: Part 1: Introduction to recursive types and catamorphisms A simple recursive type Parameterize all the…
This post is the third in a series. In the first post, I introduced “catamorphisms”, a way of creating functions for recursive types, and in the second post, we created a few catamorphism implementations. But at the end of the previous post, I noted that all the catamorphism implementations so far have had a potentially serious flaw. In this post, we’ll look at the flaw and how…
This post is the second in a series. In the previous post, I introduced “catamorphisms”, a way of creating functions for recursive types, and listed some rules which can be used to implement them mechanically. In this post, we’ll use these rules to implement catamorphisms for some other domains. Series contents Here’s the contents of this series: Part 1: Introduction to…
In this series, we’ll look at recursive types and how to use them, and on the way, we’ll look at catamorphisms, tail recursion, the difference between left and right folds, and more. Series contents Here’s the contents of this series: Part 1: Introduction to recursive types and catamorphisms A simple recursive type Parameterize all the things Introducing catamorphisms Benefits of…