简体   繁体   English

F# 类型函数和一个 [<GeneralizableValue> ] 属性

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

What is the difference between this two F# type functions:这两个 F# 类型的函数有什么区别:

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

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

Here is a good blog:这是一个很好的博客:

http://blogs.msdn.com/b/mulambda/archive/2010/05/01/value-restriction-in-f.aspx (archived here ). 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.阅读GeneralizableValue部分需要一些阅读,但如果你到达那里,我想你会理解它。 :) :)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM