F# Active Patterns as function parameters
Posted July 23, 2009
By joshua
When I first learned about active patterns in F# I thought they were pretty great. Then I saw you this F# video and learned you can patterns as function parameters. This lets you do stuff like the following. (note I stole the example from this F# video)
open System.Drawing
let (|RGB|) (color : Color) = (color.R, color.G, color.B)
let printRGB (RGB(r, g, b)) =
printfn "%d, %d, %d" r g b
printRGB Color.Red
I find this especially cool because I often have a wrapper function to do this sort of data transformation and this is far more elegant.