So i have this:
open System
open System.Linq
open Microsoft.FSharp.Collections
type Microsoft.FSharp.Collections.List<'a> with
static member (+) (First : List<'a>) (Second : List<'a>) =
First.Concat(Second)
let a = [1; 2; 3; 4; 54; 9]
let b = [3; 5; 6; 4; 54]
for x in List.(+) a b do
Console.WriteLine(x)
and I want to convert the last line into
for x in a + b do
Console.WriteLine(x)
but doing so gives me a
The type 'int list' does not support any operands named '+'
The documentation and examples on the web are flakey, and despite my google-fu i have been unable to get it to work. Basically, coming from a python background, I want to get my list manipulation syntax as terse as I am used to: it should not need more than 1 character in infix notation.
First, overriding operators should be declared in the tuple form, not in the carried form. In your case:
Second, after you fix that, the compiler raises the
"Extension members cannot provide operator overloads. Consider defining the operator as part of the type definition instead."warning. There are some workarounds which have been discussed thoroughly in Overload operator in F#: (/).