You could simplify this considerably by using a dictionary of named functions.

1
2
3
4
5
6
7
8
let getOps (x:double) =
  dict [ 
    "Add",      ((+) x)
    "Multiply", ((*) x) 
  ]

let test = getOps 5.0
5.0 |> test.["Add"] //10.0

You could even define a dynamic lookup operator for dictionary to tighten the syntax:

1
let (?) (d:IDictionary<_,_>) key = d.[key]

Then you can do:

1
test?Add 5.0
By on 10/13/2011 8:54 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper