Operator overloading with seq <'T>
In a project I'm experimenting with, I'm constantly multiplying the elements of the sequence. I wanted to create a statement like this:
let (.*) (a:seq<'T>) (b:seq<'T>) = Seq.map2 (*) a b
However, in FSI, it returns:
val ( .* ) : a:seq<int> -> b:seq<int> -> seq<int>
And the following:
seq [1.0;2.0] .* seq [3.0;4.0];; -----^^^ stdin(16,6): error FS0001: This expression was expected to have type int but here has type float
How can I get the operator to work with generic seq <'T> (assuming T supports multiplication)?
+3
source share
1 answer