Is there a list of valid prefix operator names somewhere? I haven’t been able to find one, but I’ve noticed that some operators that used to be valid as prefix operators in the last CTP are no longer valid in the RC.
let (~--) (str:string) = [str];;
-----^^^
stdin(4,6): error FS1208: Invalid operator definition.
Prefix operator definitions must use a valid prefix operator name.
Edit:
Brian’s link includes the following list of valid prefix operators:
! (or repetitions of !)
~ (or repetitions of ~)
+
-
+.
-.
%
%%
&
&&
My link below lists only these operators:
~
!
?
A quick test shows that the MSDN docs do not seem to be current with the language spec. Thanks, Brian.
See
http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc245030784
which spells out the rules. I’ve quoted some of it below. (See also
http://msdn.microsoft.com/en-us/library/dd233228(VS.100).aspx
but I think it doesn’t have the full rules.)
The following symbolic-op tokens can be used to form expressions:
Operators made of the following are always prefix operators:
Other operators beginning with these characters are not permitted.
The operators +, -, +., -., %, &, && and may be used as both prefix and infix operators. When used as prefix operators these operators have an implicit operator name with ~ prepended. For example, -x is parsed as an application of the operator ~- to the expression x. This name is also used when giving definitions for these prefix operators:
This means that these prefix operators are defined with the ~ character added: