Generic type parameters

F# also supports a generic parameter type. We can specify multiple generic type parameters separated by a comma. The syntax of a generic parameter declaration is as follows:

type MyGenericClassExample<'a> (x: 'a) =   do printfn "%A" x

The type of the parameter infers where it is used. In the following code, we call the MyGenericClassExample method and pass a sequence of tuples, so here the parameter type became a sequence of tuples:

let g1 = MyGenericClassExample( seq { for i in 1 .. 10 -> (i, i*i) } )

Get .NET Core 2.0 By Example 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.