I found this code in the excellent book F# Design Patterns
by Gene Belitski:
let (| `` I'm active pattern `` |) x = x + 2
let (`` I'm active pattern `` y) = 40
(*
val ( |`` I'm active pattern ``| ) : x:int -> int
val y : int = 42
*)
The author recognizes that this is
"a slightly mind boggling example that becomes clear if you remember that the let binding of a value is a corner case of pattern matching based data disassembling, so I'm active pattern
gets applied to input argument 40 and binds the result 42 to x."
I don't get it. Why does I'm active pattern
gets applied to 40, given that 40 is on the right-hand side? Intuitively I would guess that y = 38, not 42, looking at the expression let (`` I'm active pattern `` y) = 40
as an implicit function.
Can anyone explain?