In F# what is the type annotation for a typed list (e..g list of int)? With a simple function I can do annotations as follows:
let square(x:int) = …
I’ve annotated x as an int type. But what if I want to do a type annotation for an int list? For example, let’s say I have a max function that expects a list – how would I do a type annotation for it?
let max(numbers:??) = …
There are two options:
The first version uses syntax that is inherited from OCaml (and is frequently used for primitive F# types such as lists). The second version uses .NET syntax (and is more frequently used for .NET types or when writing object-oriented code in F#). However, both of them mean exactly the same thing.
In any case, the form of type annotation is always
(<something> : <type>)where<something>is either a pattern (as in parameter list) or an expression. This means thatint listandlist<int>are just names of types. F# Interactive prints the type if you enter some value, so you can use this to learn more about how type names are written: