Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# type functions and a [<GeneralizableValue>] attribute

What is the difference between this two F# type functions:

let defaultInstance1<'a when 'a:(new: unit->'a)> = new 'a()

[<GeneralizableValue>]
let defaultInstance2<'a when 'a:(new: unit->'a)> = new 'a()
like image 337
controlflow Avatar asked Dec 16 '22 20:12

controlflow


2 Answers

Here is a good blog:

http://blogs.msdn.com/b/mulambda/archive/2010/05/01/value-restriction-in-f.aspx (archived here).

It takes a bit of reading to get to the GeneralizableValue part, but if you get there, I think you will understand it. :)

like image 75
Brian Avatar answered Jan 05 '23 22:01

Brian


let defaultInstance1<'a when 'a:(new: unit->'a)> = new 'a()

[<GeneralizableValue>]
let defaultInstance2<'a when 'a:(new: unit->'a)> = new 'a()

let x1 = defaultInstance1 // value restriction
let x2 = defaultInstance2
like image 30
desco Avatar answered Jan 05 '23 22:01

desco