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

大憨熊 提交于 2019-12-10 07:43:20

问题


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()

回答1:


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



回答2:


Here is a good blog:

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

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



来源:https://stackoverflow.com/questions/3963568/f-type-functions-and-a-generalizablevalue-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!