Why is $ permitted, but $$ or <$> forbidden as an operator (FS0035), and what does $ special do?

$ allowed in the user statement, but if you try to use $$ , <$> or, for example, ~$% as the name of the operator, you will get the following error:

error FS0035: this construct is deprecated: "$" is not allowed as a character in operator names and is reserved for future use

$ clearly also has a $ in the name , but it works, why? I.e:.

 let inline ( $ ) fy = fy // using it works just fine: let test = let add x = x + 1 add $ 12 

I see $ lot in online examples and, apparently, as a specific operator. What is this relation or role for $ (i.e. In Haskell or OCaml) and what to do <$> if it is allowed (to edit)?

An attempt to fool the system by creating a function such as op_DollarDollar does not fly, syntax checking is also performed on the call site. Although, for example, this trick works with other (legal) operators:

 // works let inline op_BarQmark fy = fy let test = let add x = x + 1 add |? 12 // also works: let inline op_Dollar fy = fy let test = let add x = seq { yield x + 1 } add $ 12 
+6
source share
1 answer

At this point, there is some inconsistency in the F # specification . Section 3.7 of the F # specification defines symbolic operators as

 regexp first-op-char = !%&*+-./<=>@^|~ regexp op-char = first-op-char | ? token quote-op-left = | <@ <@@ token quote-op-right = | @> @@> token symbolic-op = | ? | ?<- | first-op-char op-char* | quote-op-left | quote-op-right 

(and $ also does not appear as a symbolic keyword in section 3.6), which indicates that the compiler did not accept ( $ ) as the operator.

However, section 4.4 (which covers operator priority) includes the following definitions:

 infix-or-prefix-op := +, -, +., -., %, &, && prefix-op := infix-or-prefix-op ~ ~~ ~~~ (and any repetitions of ~) !OP (except !=) infix-op := infix-or-prefix-op -OP +OP || <OP >OP = |OP &OP ^OP *OP /OP %OP != (or any of these preceded by one or more '.') := :: $ or ? 

and the following table of priorities and associativity contains $ (but does not indicate that $ can be displayed as one character in any longer character operator). Consider making a mistake so that the specification can be agreed upon anyway.

+4
source

Source: https://habr.com/ru/post/1013476/


All Articles