Short answer
This is the correct syntax:
let count<'a> : 'a list -> int = List.fold (fun t _ -> t + 1) 0
Description
This is not a type annotation that helps; it is a general parameter.
This compiles (and even works, sort of):
let count<'a> = List.fold (fun t _ -> t + 1) 0
FS0030 , . , ( ), . , , . , , , , , , .
, . , F # count, , obj list -> int.
? - :
let count<'a> = List.fold (fun t _ -> t + 1) 0
let c = count [1..5]
count - int list -> int.
? : -)
let count<'a> = List.fold (fun t _ -> t + 1) 0
let c = count [1..5]
let c2 = count ["a"; "b"; "c"]
, , , "a", "b" "c" int.
WTF?
F # - "" , . count obj list -> int (obj ), int list, int list -> int. string list , .
:
let add x y = x + y
add 2.0 4.5
add "a" "b"
int -> int -> int, , add float -> float -> float ( ), , -, .
, :
let count<'a> : 'a list -> int = List.fold (fun t _ -> t + 1) 0
count .