Overloading + operator in F#

前端 未结 5 2152
半阙折子戏
半阙折子戏 2020-12-18 05:34

So i have this:

open System
open System.Linq
open Microsoft.FSharp.Collections
type Microsoft.FSharp.Collections.List<\'a> with
    static member (+) (         


        
5条回答
  •  攒了一身酷
    2020-12-18 05:45

    First, overriding operators should be declared in the tuple form, not in the carried form. In your case:

    type Microsoft.FSharp.Collections.List<'a> with
        static member (+) (first: List<'a>, second: List<'a>) =
            first.Concat(second)
    

    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#: (/).

提交回复
热议问题