sthiers
sthiers

Reputation: 3531

In F#, how to instantiate a generic type definition?

How can I instantiate a generic type definition in F#? (i.e. an instance of Type class whose IsGenericTypeDefinition property returns true).

Example in C#:

Type d1 = typeof(Dictionary<,>);

Note:

typeof<Dictionary<'T,'U>> 

does not work. 'T and 'U are interpreted as object.

Upvotes: 2

Views: 140

Answers (1)

TheQuickBrownFox
TheQuickBrownFox

Reputation: 10624

let t = typedefof<Dictionary<_,_>>
t.IsGenericTypeDefinition // true

This is not the same as typeof. Note the def in the middle :)

Upvotes: 3

Related Questions