Overloading + operator in F# -


so have this:

open system open system.linq open microsoft.fsharp.collections type microsoft.fsharp.collections.list<'a>     static member (+) (first : list<'a>) (second : list<'a>) =         first.concat(second)  let = [1; 2; 3; 4; 54; 9] let b = [3; 5; 6; 4; 54]   x in list.(+) b     console.writeline(x) 

and want convert last line into

for x in + b     console.writeline(x) 

but doing gives me

the type 'int list' not support operands named '+' 

the documentation , examples on web flakey, , despite google-fu have been unable work. basically, coming python background, want list manipulation syntax terse used to: should not need more 1 character in infix notation.

first, overriding operators should declared in tuple form, not in carried form. in case:

type microsoft.fsharp.collections.list<'a>     static member (+) (first: list<'a>, second: list<'a>) =         first.concat(second) 

second, after fix that, compiler raises "extension members cannot provide operator overloads. consider defining operator part of type definition instead." warning. there workarounds have been discussed thoroughly in overload operator in f#: (/).


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -