Mavnn's blog

Stuff from my brain

Advent 2016

Each year I like to make my F# advent post centered around an aspect of the actual Christmas story, so this year I decided to look at the actual text of the Christmas story.

There are a couple of direct historical accounts recorded in the bible, in the Gospels of Mark and Luke. But Jesus's birth is a central point of the overall biblical story, with links to the Old Testiment books written before and referenced in places through the New Testiment.

Sounds like a graph to me, so lets see how far we can take some analysis.

Fortunately, someone has already produced a text file with a whole bunch of cross references in a nice regular format. So all we need to get started is a nice parser. We'll also want to pull in some metadata about the structure of the bible as a book in JSON format from the people at

Time to reference some dependencies to do our heavy lifting for us: FParsec for parsing, and FSharp.Data for the JSON type provider.

I'm writing this in the excellent Jupyter F# notebook (and then exporting it as markdown), so I'll use their Paket helpers to grab my dependencies (this should work on the Azure notebooks as well, although I've only tried it locally).

Video and Slides for “From the Ivory Tower”

I spoke this morning at F# Exchange and this being SkillsMatter they've published the recording already.

It's a nice short talk, weighing in at about 15 minutes. So grab yourself a coffee and take a short tour of how some of F#'s more esoteric features (active patterns, computational expressions, quotations and type providers) have been used to solve real problems in the real world.

Video here:

Slides here:

Expanding Existing Computational Expressions

This is a "just because you can" post, although frankly bizarrely I have a genuine use case for this.

Let the mind melting commence!

Computational expressions in F# provide nice sugared syntax for monadic data structures such as seq and async; but the specific expressions are not built in language features. You can build your own.

Which is fun and all, but you know what's even more fun? Well, it turns out that there's no requirements for computational expressions to be actual monads. Even more fun than that is that the bind operation (used when you invoke let! syntax) is a member on a class - and it is valid both for it to be an extension method, and for it to be overloaded. You can even add custom operators to computational expressions using the extension method trick.

Which means you can do some very interesting things indeed to existing computational expressions. Let's try it out!

Type Provider Pro-Tip: Using Dictionary

During the Type Provider Live recording, Ryan asked me about basing erased provided types on dictionary types, and then exposing nicely typed properties to access data stored within the dictionary.

This will sound familiar to users of a number of dynamically typed languages as in many cases objects in these languages are just dictionaries under the hood.

This is such a common thing to be doing in a type provider that I thought it was worth writing up a working example that can then be modified to your individual situation. I've presented the entire listing below with comments, but there is one particular trick I'll explain in a bit more detail. Let's have a look at let bindings in quotations!

Type Providers Live - the Movie

I recently gave a live streamed tutorial on building type providers, which I've embedded below. Apologies for the sound; apparently Google Hangouts added a feature I was unaware of until after the stream started which mutes your microphone whenever you type.

Fortunately I think enough was preserved to be useful, and (amazingly!) all of the demonstrations actually worked.

If you'd like to try things out for yourself, there's a github repository at which contains 6 individual fsx files, one for each new feature added to the type provider.

There's a bunch of other type provider information scattered around this blog, if you're interested just click the "typeprovider" tag.

EmParsec Embedded Parser Library

You can find EmParsec on GitHub:

Type providers, by their very nature, tend to access data external to the .net ecosystem. It can also be very awkward technically to make use of dependencies during the actual type generation process.

This is rather a pity, because accessing all of that external data is much nicer and easier when you have a decent parser to do it with. And F# has very, very nice parser support via the FParsec library. Instead, many (most?) type providers end up creating mini-one shot parsers which can be a bit slow to write and don't tend to have features that come for free in a more complete solution such as nice error reporting.

Writing yet an other parser (YAOP) this week I decided that enough was enough. What I needed was a shared resource that people could pool improvements for that could be easily embedded in projects like type providers were it isn't desirable (or sometimes possible) to take external binary dependencies.

So I built it.

Angels From the Realms of Glory

An angel of the Lord appeared to them, and the glory of the Lord shone around them, and they were terrified. Luke 2:9

It's that time of year again, where the F# community get together to source a collection of weird, wonderful and occasionally useful blog posts on life, the universe and sometimes Christmas.

As mentioned in last years post, I like to go back to the source when it comes to advent posts, so lets dive back into the book of Luke (and learn about agent based programming as we go).

Annoucing @mavnn Ltd

As I hinted in the last post, new (and to me) exciting things are afoot. I'm very pleased to announce the formation of @mavnn ltd!

That's great, but what is it going to do?

I'm glad you asked! @mavnn ltd is the continuation of a lot of the things I've come to care most about over my years in software development: building reliable, maintainable and well crafted code and teaching others to do the same.

You can check out the web page for more details, but basically there's three streams to what the company will be providing:

  • Building code that works
  • Offering consultancy on how your team can build better software with less friction (especially around automating build, deployment and testing)
  • Giving training in skills that will allow teams to build solid software using functional programming techniques and thinking

What are doing already?

I'm glad you asked that too! Stream one of the company ("Building code that works") is already well under way - we're very pleased to say that @mavnn ltd's first customer is Logibit, where I'm helping Henrik and Mikko build out the Qvitoo platform.

Although it's always nice as a small company to have contracts, we're particularly pleased to be working with Logibit: firstly because they're great people to work with - you don't need to work for them to find that out, just get involved in any of the myriad open source projects they're involved in!

Secondly, as a company they embody the things that @mavnn stands for: leveraging the ideas behind functional programming in deeply practical ways to build software that solves real world problems, and does so exactly as designed.

Can I hire you?

Yes! To avoid disappointment, though, I should make it clear that we have some ongoing contractual agreements and so will not be accepting ongoing full time contracts for the foreseeable future.

Training, consultancy, ongoing part time and short term full time contracts are all up for grabs though - including remotely and in some cases internationally as evidenced by our co-operation with Logibit. Contact us to find out more.

Beginnings and Endings

There's the normal mix of excitement and sadness as I announce that today is my last day with my current employers, 15below.

Sadness because the people here are great and I've learned an unbelievable amount while working here. Excitement because there's exciting things happening for the future. What are these brave new vistas? Well, that will have to wait for next week.

But for now, it's time for a brief thank you and review of what I'm leaving.

Thanks 15below for:

  • being an incredibly flexible, generous & family friendly employer
  • Lots and lots of learning from existing code, conversations, other people delivering internal training, letting me invite external speakers, and the rest
  • releasing some open source, even while in an "enterprise" market: github
  • letting me coordinate the internal developer education
  • sponsoring a bunch of conference speaking (there's more!)
  • trusting me to convert the build from msbuild to FAKE and kick start the journey to automated deployment (which was a slow and painful one in msbuild world…)
  • picking solid, generous people as staff - that's just one example from many, and the company often matches the giving of the staff

I'm hoping my last piece of work here, converting our main product repository to use Paket rather than nuget for dependency management is a gift that will keep on giving to the rest of the devs; here's to many more years of 15below bringing tech to the travel industry.

EasyNetQ Process Management

TL;DR: I wrote a EasyNetQ aware process manager library. Read down for some examples, and leave feedback if you think anything should change before it's released.

EasyNetQ is a nice little .net client library for RabbitMQ. Originally designed for introducing Rabbit (and the concepts of a bus based architecture) to a company and programmers who hadn't previously used them before, it uses conventions to set up exchanges and queues - basing them on the names of the .net types that are being sent and subscribe to.

For example (from the EasyNetQ homepage):


Will publish a message of type "MyMessage". Generally there's no need to actually specify the type here, C# will infer it for you, but it makes the example clearer.

Other services can subscribe to "MyMessage" like so:

bus.Subscribe<MyMessage>("my_subscription_id", msg =>