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) } )
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset