Type hints make the type of a value, parameter, or result visible in code or in an editor. In F#, the compiler usually infers those types, so annotations are optional rather than routine. An explicit annotation states an intention—such as `int`—and the compiler checks that the expression agrees. The annotation follows the symbol name, keeping the declaration close to the value being described. section 3.2.2 section 3.1.1
Inference first, annotation when useful
These bindings compile the same way: `let i = 10` and `let i : int = 10`. The second form exposes the inferred intent. Writing `let i : string = 10` instead produces an error because the value is an integer, not a string. Function parameters and return values can be annotated similarly: `let add (a:int) (b:int) : int = a + b`. section 3.2.2
Prefer inference for ordinary code: repeating types adds symbols without making equivalent code safer or clearer. Use an annotation to communicate a meaningful boundary, satisfy an inference limitation, or temporarily steer the compiler toward the real mistake. After correcting the problem, a diagnostic annotation can often be removed. section 3.1.1 section 3.2.4
Listing 3.4 Working with type annotations
let add (a:int) (b:int) : int = #1
let answer : int = a + b #2
answer #3
Compare parameter, local-value, and return annotations in one small function, then remove them to see which types F# can infer unaided. section 3.2.2
Inference can need help around object-oriented member access. A function calling `DateTime.AddDays`, for example, requires its date parameter to be declared as `System.DateTime`; once that type is established, later functions using the first function can infer it downstream. This keeps annotations at the boundary instead of spreading them through every call. section 3.2.5
Annotations are also a focused debugging tool. If an early comparison causes a parameter to be inferred as `string`, calls that supply integers may produce several downstream errors. Marking the parameter as `int` moves the error to the incompatible comparison. Start with the first reported error, since fixing it can clear later messages. section 3.2.4
Editor hints expose inferred types without cluttering source code. CodeLens and LineLens can update type information as expressions change, including custom types and functions. In collection pipelines, generated hints at each stage reveal intermediate result types and help identify functions whose output and input types do not match. section 3.2.2 section 7.2.2
















