Standards for using custom operators

I am currently reading real-world functional programming, and it briefly mentions in-fix operators as one of the main advantages of user-defined operators. Are there any standards for using or not having custom operators in F #? I am looking for answers equivalent to these .

For reference, here is a quote that @JohnPalmer refers to here :

3.8 Definitions of the operator 

Avoid defining custom symbolic statements in F # library constructs.

Custom operators are necessary in some situations and are very useful notational devices in the body of the implementation code. For new users of a library, a named function is often easier to use. In addition, custom symbolic operators can be difficult to document, and it is more difficult for users to find help information about operators due to existing restrictions in IDEs and search engines.

As a result, it is usually best to publish your functionality as named functions and members.

+4
source share
1 answer

Custom infix operators are a nice feature in some situations, but when you use them, you have to be very careful that your code is readable, so most of the time, the recommendation from the F # design guidelines is recommended. If I wrote "Functional Programming in the Real World" again, I would be a little less interested in them, because they really should be used carefully :-).

However, there are several F # libraries that make good use of user-defined operators, and sometimes they work very well. I think FParsec (the library of parser combinators) is one case - although there may be too many of them. Another example is the XML DSL , which uses @= .

In general, when you write a regular F # library, you probably do not want to open it. However, when you write a domain-specific language, custom operators may be useful.

+3
source

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


All Articles