Type inference

I have already outlined type inference earlier in the chapter. It is a feature of F# (as well as many other languages: C#, to begin with) that stems from its property of being statically typed. By following the natural code flow direction from top to bottom and from left to right, the F# compiler is capable of deriving types of values present in the code, including function types. This ability, in turn, allows you to omit explicit type declarations from the F# code. In the end, the code can be written faster, is quite succinct, and if it compiles, is consistent type-wise.

Relying on type inference is not mandatory when writing the F# code. Adding an explicit declaration to the code may be especially meaningful in the following scenarios: ...

Get F# 4.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.