# Pondering a prescription for pattern matching prevalance

In which I ramble on about how my thoughts on pattern matching have changed over the years.

# Currying vs. partial application

When I first came across the terms "currying" and "partial application" I was a bit confused about the difference. Here is my attempt at an explanation1. I’m not 100% confident of my understanding, so please point out any inconsistencies – I’m happy to be corrected :).

C and C-style languages like C++, Java, and C# tend to have method types written like this:

Other typed languages and programming papers use a notation more like this:

I found it took a bit of getting used to, but I now much prefer to read and write this style. I think it is worth becoming familiar with, as it is used in quite a few languages1 and in all the programming papers I’ve seen. So here’s a quick guide on how to read this style of type annotation.

# The Apply pattern

I really enjoy trying to understand how and why things like work, but for this post I’m going to try to skip all that wonderful stuff and instead give a practical outline of how to use a very useful pattern arising from applicative functors.

I’ve found this pattern incredibly useful in F#, Swift and Haskell. The examples here are in F#, but as far as I can tell we can use it anywhere that has generic types and higher-order functions.

# Git tidbit: Comparing different paths across branches or commits

Today I updated a library version in a project, which changed the path from packages/FSharp.Formatting.CommandTool-2.8.0 to packages/FSharpFormatting.CommandTool-2.9.1. We’d also taken our own copies of some templates in the package, and I wanted to check if there were any differences between -2.8.0\templates and -2.9.1\templates that I should port across.

Rather than my usual fumbling about (check out both, copy, diff) I thought I’d try to learn the necessary Git incantation to compare the paths. And then blog it, so that when I forget I’ll have a quick reference handy for next time. :)

# F# type signature gotchas

Today I was speaking with a colleague about some F#, and he pointed out a few gotchas with F# type signatures, especially if you’ve spent some time with Haskell (and not OCaml or other ML-ish language).

# F#: Pattern matching on field literals

F# gave me the following error when working with some C# code:

error FS0729: This field is not a literal and cannot be used in a pattern 

I’m not entirely sure it’s a good idea, but I managed to work around this using a partial active pattern.

# D3 newbie updates a bar chart

I’ve been trying to learn D3.js via Mike Bostock’s excellent "Let’s make a bar chart" tutorial series. This post is my attempt to extend that example to handle data updates.

# A simple circuit, an Arduino, and Haskell

I recently had loads of fun attending a Nodebots AU event in Sydney. (Thanks a lot to Damon and Andrew for organising, and NICTA for the venue!) I got to muck around with some simple circuits and drive them with Javascript. Towards the end of the day I was running out of time and creativity to do anything fancy, so I decided to see if I could get one of the circuits working with Haskell.