Search code examples
f#custom-operator

Is it possible to define the ** operator in F#


let (**) ls1 ls2 = List.intersect ls1 ls2

does not work because (**) is considered a comment. Is there any escape possibility?


Solution

  • You can add whitespace inside the parentheses, like this:

    let ( ** ) ls1 ls2 = List.intersect ls1 ls2
    

    Keep in mind, however, that ** is a standard F# operator for "power":

    2 ** 3 = 8
    

    So if you redefine it like this in the global context, you will not be able to use it in the "power" sense.