According to MSDN, the colon cannot actually be used in the operator name. This seems to run counter to the F # spec from FSharp.org, I'm not sure what is going on there. But we can check that in FSI:
> let ( >:> ) ab = a+b Script.fsx(1,7): error FS0035: This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use
If you look at how List<'T> defined , you will find that (::) is actually not a statement, but a constructor case:
type List<'T> = | ( [] ) | ( :: ) of Head: 'T * Tail: 'T list
And, of course, you can define your own DU type with a name as the constructor name:
> type A = > | ( :: ) of string * int > | A of int > > let a = "abc" :: 5 val a : A = Cons ("abc",5)
Now, oddly enough, if I try to use a different operator-ish-look-name as the case constructor, I get this error:
> type A = | ( |> ) of string * int Script.fsx(1,14): error FS0053: Discriminated union cases and exception labels must be uppercase identifiers
This means that (::) is somehow special (and, by the way, this is ([]) ).
So the bottom line is no, you cannot do this.
But why do you need this? Can you possibly agree to a more acceptable operator name that still expresses the semantics of "const" - for example, (<+>) ?
Fyodor soikin
source share