When creating a list, list items must be of the same type. This means that you cannot create a list containing Holder<int>and Holder<float>.
If you want to create a mixed type list, you can either define a discriminatory union:
type Value =
| Float of Holder<float>
| Int of Holder<int>
And create a list of types Valueusing:
let list = [Int intVal; Float floatVal]
, (, Name) . :
type IHolder =
abstract Name : string
type Holder<'data> =
{ Data : 'data
Name : string }
interface IHolder with
member x.Name = x.Name
Holder<_>, IHolder:
let list = [intVal :> IHolder; floatVal :> IHolder]
for h in list do printfn "%s" h.Name
, . , , .