3 people like it.

Functions not so first class in active patterns

It seems that you can't pass anonymous functions as parameters to active patterns.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
let (|Apply|) f input = f input

let addFunc = fun a -> a+5

let add5 (Apply addFunc res) = res

let add5' (Apply ((+) 5) res) = res

//alas: let add5'' (Apply (fun a -> a + 5) res) = res 
val f : ('a -> 'b)
val input : 'a
val addFunc : a:int -> int

Full name: Script.addFunc
val a : int
val add5 : int -> int

Full name: Script.add5
active recognizer Apply: ('a -> 'b) -> 'a -> 'b

Full name: Script.( |Apply| )
val res : int
val add5' : int -> int

Full name: Script.add5'

More information

Link:http://fssnip.net/5N
Posted:13 years ago
Author:Kurt Schelfthout
Tags: active patterns , anonymous functions