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 will learn how to create F# types that integrate better with other object-oriented languages like C# when consumed: for example, adding operator overloading to allow your types to be used with symbolic code as well as adding events to your code to allow consumers to receive notifications when certain actions occur. This not only enables you to be more expressive in your F# code, but it also reduces the friction with non-F# developers when sharing your code.
Using a symbolic notation for manipulating objects can simplify your
code by eliminating the need to call methods like
Remove, instead using more intuitive
-. 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, like
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 ...