所以我有這樣的:重載+運營商在F#
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)
,我想最後一行轉換成
for x in a + b do
Console.WriteLine(x)
但這樣做給了我一個
The type 'int list' does not support any operands named '+'
的文檔和在網絡上的例子是flaky,儘管我谷歌福,我一直無法得到它的工作。基本上,來自python背景,我想讓我的列表操作語法像我習慣的那樣簡潔:它不應該需要超過1個字符的中綴表示法。
嗯我從來不知道這個限制;謝謝! –
@LiHaoyi但有一種方法來解決這個限制,請參閱我的答案。 – Gustavo