Overload operator in F#: (/)

后端 未结 4 1136
情书的邮戳
情书的邮戳 2020-12-17 15:08

I would like to overload the (/) operator in F# for strings and preserve the meaning for numbers.

/// Combines to path strings
let (/) path1 path2 = Path.Com         


        
4条回答
  •  天命终不由人
    2020-12-17 16:03

    Actually you can.

    Try this:

    open System.IO
    
    type DivExtension = DivExtension with
        static member inline (=>) (x             , DivExtension) = fun y -> x / y
        static member        (=>) (x             , DivExtension) = fun y -> Path.Combine(x, y)
        static member        (=>) (x:DivExtension, DivExtension) = fun DivExtension -> x
    
    let inline (/) x y = (x => DivExtension) y
    

提交回复
热议问题