Updated with Tchepak's change to remove the parameterised active pattern, and use tuple instead