what is use cases of F# explicit type parameters? -


as know, explicit type parameters in value definitions 1 way overcome "value restriction" problem.
there cases when need use them?

upd: mean "explicitly generic constructs", type parameter enclosed in angle brackets, i.e.

let f<'t> x = x 

this rare, when want prevent further generalization (§14.6.7):

explicit type parameter definitions on value , member definitions can affect process of type inference , generalization. in particular, declaration includes explicit generic parameters not generalized beyond generic parameters. example, consider function:

let f<'t> (x : 't) y = x 

during type inference, result in function of following type, '_b type inference variable yet resolved.

f<'t> : 't -> '_b -> '_b 

to permit generalization @ these definitions, either remove explicit generic parameters (if can inferred), or use required number of parameters, following example shows:

let throw<'t,'u> (x:'t) (y:'u) = x 

of course, accomplish type annotations.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -