A few generics terms

I've been diving into generics a bit more deeply, and I'd like to share some of the
new terminology that will be floating around.

Open Type

An open type is a generic type that you've defined. List<T> is a good example.
It's called "open" because it's not fully defined without knowing what T is, and therefore
you can never have an instance of this type.

Type Parameter

The type placeholder that you use when writing a generic type. In List<T>,
T is the type parameter.

Constructed Type

A constructed type is what you get when you specify a type for a type parameter. List<int>
is a constructed type, and you can create instances of it.

Type Argument

The actual type you use instead of the type parameter when creating a construct type .
In List<int>, int is the type argument.

Generic Method

A method that has a type parameter on it.

static int Process<T>(T t);

is an example


Strictly speaking, the number of parameters to a method. In generic terms, it's the
number of type parameters on a generic type or method. ArrayList has an arity of zero,
while List<T> has an arity of one.

Comments (11)

  1. Anonymous says:

    I was wondering if there was a way to alias or "typedef" these generics to shorter names. Imagine typing something like SomeLongNameWithALotParams<Type1, Type2, Type3, Type4>? I only could think from deriving a empty subclass to do that i.e.:
    class ShortName : SomeLongNameWithALotParams<Type1, Type2, Type3, Type4>

  2. chris says:

    Umm, are you sure ‘arity’ is a real word? I don’t want to go to work tomorrow and have people laugh at me beacuse of this. (Well at least not for any other reasons…)

  3. http://dictionary.reference.com/search?q=arity

    "<programming> The number of arguments a function or
    operator takes. In some languages functions may have
    variable arity which sometimes means their last or only
    argument is actually a list of arguments."

  4. Eric says:

    We don’t support typedef, so using another type is a reasonable solution.

  5. Richard Blewett says:

    Couldn’t you simply use "using" to alias the type? i.e.

    using ShortName = SomeLongNameWithALotParams<Type1, Type2, Type3, Type4>;

    its the moral equivelent of a TypeDef

  6. Frans Bouma says:

    Eric, who cookes up these names? 🙂
    Isn’t a constructed type also a ‘closed’ type, since its opposite is the open type ? Why not call the open type an ‘unconstructed’ type?

    The ‘int’ in List<int> is the type parameter VALUE, since it gives value to the parameter TYPE T. Like: Foo(int bar), ‘bar’ is the parameter, and: Foo(3), 3 is the parameter value for bar. Using the names you presented will confuse a lot of people while it is unnecessary. If two things are eachothers opposites, call them as if they’re opposites: Open X, Closed X etc..

  7. Ryan Heath says:

    Hmm, Frans is reading my mind 🙂
    I was just going to ask the same questions

  8. Ivan Towlson says:

    Do we also need a name for the restriction on the type argument e.g. Collection<T : ICollectible> — what would I call ICollectible?

  9. Eric Gunnerson says:

    Lots of comments to respond to:

    On the open vs constructed nomenclature, I wasn’t around when that came up, so I don’t really know why we chose that. It may be that there’s a difference between a type that would be called closed and one that’s actually constructed by the JIT, and that I just don’t know it yet.

    On Frans’ comment on what to call "int" in "List<int>", it’s fairly common – at least in language circles – to talk about parameters and arguments, and we thought that using that analogy was a good idea.

    Onto Ivan’s question. What you’re talking about is called a constraint, which is a "term of art" that was already in use in generics circles, IIRC (though I’m pretty sure the syntax is different than what you mention).

  10. Mike Dunn says:

    I’m hoping for a new way of representing the type parameters in sample code, something more meaningful than "T" 😉 I swear, the constant things called T in C++ template examples made it hard for me to grok templates at all.

Skip to main content