Search code examples
genericsf#attributestype-systems

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

Solution

  • 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