This chapter could also be called “being functional in an object-oriented world.” By now you’ve mastered the F# syntax and style, but there is still plenty to be said about using F# in the object-oriented landscape of the .NET platform.
In this chapter, you learn how to create F# types that integrate better with other object-oriented languages like C#. For example, with operator overloading, you can allow your types to be used with symbolic code. Also, events enable your classes to notify consumers to receive notifications when certain actions occur. This not only enables you to be more expressive in your F# code, but also reduces the friction with non-F# developers when sharing your code.
A symbolic notation for manipulating objects can simplify your code by
eliminating methods like
Remove, and instead using more
intuitive counterparts like
-. Also, if an object represents a
collection of data, being able to index directly into it with the
.[ ] or
] notation can make it much easier to access the
data an object holds.
Operator overloading is a term used for adding new meaning to an existing operator,
-. Instead of only working on primitive types,
you can overload those operators to accept custom
types you create. Operator overloading in F# can be done by simply
adding a static method to a type. After that, you can use the operator as if it natively supported the type. The ...