I want to implement (simple) adding math functions to F #, which means:
Imagine that F is the field of all functions that map an element A to an element B : 
Then my "add function" should be defined as follows: 
I tried the following code to implement adding a function as an operator !+ :
let inline (!+) (f1 : ^a -> ^b, f2 : ^a -> ^b) : ^a -> ^b = let f (x : ^a) : ^b = (f1 x) + (f2 x) f
However, if I want to compile the following lines, I will get an error:
let f1 x : float = -x // negate x let f2 x : float = 2. * x // multiply by 2 let f3 = f1 !+ f2 //error : Expexceted `float`, got `'a -> 'b`
I am sure that this is caused by some simple logical error, but I still could not find it.
So my question is: how to determine the addition of a function in F #?
source share