Overload operator in F#

Posted by forki23 on Stack Overflow See other posts from Stack Overflow or by forki23
Published on 2010-05-11T15:40:18Z Indexed on 2010/05/11 15:44 UTC
Read the original article Hit count: 322

Filed under:
|

Hi,

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.Combine(path1,path2)

let x = 3 / 4 // doesn't compile

If I try the following I get "Warning 29 Extension members cannot provide operator overloads. Consider defining the operator as part of the type definition instead."

/// Combines to path strings
type System.String with
  static member (/) (path1,path2) = Path.Combine(path1,path2)

Any ideas?

Regards, forki

© Stack Overflow or respective owner

Related posts about F#

Related posts about operator-overloading