I don't know how to phrase this better, but I remember reading an article about type theory, that categorized the values being received by a function and the values being sent back from the functions.

The example was something like:

T2 function(arg T1)

In this example T1 would be a received type, and T2 would be a sent type. And the rule of thumb for engineers was "make T1 as generic as possible, since it is 'received', and T2 as specific as possible since it is 'sent'." For example:

Array<int64> function(arg Iterable<Number>)

The goal is for the caller to use any type they want but fits the function, and use all the available methods from the returned value.

It was getting trickier with callbacks, for example, in the case of:

T3 function2(callback Callback<T1, T2>)  # Callback takes T1 and returns T2

T1 is the sent type, and T2 was the type received. So T1 should be as specific as possible, while T2 should be as generic as possible.

The reasoning behind it was that T1 is "generated" by the function2, while T2 is "passed" to function2.

I know that there is a "scientific" name on whether the value of the type is "sent" or "received" by the function, but I can't find it.

  • 1
    You're just looking for the common terminology, right? If so, it'd be "return type" (which is the type of the returned value) and "parameter type" (for the type of a parameter/argument).
    – Nat
    Jul 27 '20 at 14:51
  • 2
    If you want to talk to programmers rather than mathematicians, I'd use "parameter type" and "return type".
    – Steve
    Jul 27 '20 at 20:56

The set of valid inputs to a mathematical function is the domain, and the valid outputs the codomain or range. These should more or less equate to the values contrained by the types of your sent/received nomencleture with the possible caveat that there might be values you don't want to consider as part of the domain even if the type says they are (e.g. null, depending on language) and the codmain could easily be a small subset of the output type.

I'd also be wary about using these terms on something that wasn't at least approaching a function in the mathematical sense (ideally a pure, total function). As indicated in the comments for normally progammery code argument type/return type are probably better


An input type to a function is contravariant, whilst a return type is covariant; see, for example, the Wikipedia article on covariance and contravariance (particularly for function types).

  • 1
    "Variance refers to how subtyping between more complex types relates to subtyping between their components" - this is not the case here
    – user253751
    Jul 27 '20 at 12:10
  • Did you read the section on function types? It's describing exactly the situation asked for in the original question.
    – varkor
    Jul 27 '20 at 12:18
  • It is about whether one function type is convertible to another.
    – user253751
    Jul 27 '20 at 12:27
  • The wording in the question "T1 as generic as possible" is equivalent to asking that T1 should be a superclass of anything on which the function should be called. Picking types that are generic or specific only makes sense in a language in which there is a notion of subtype (even if it's not explicit). A type A is "convertible" to a type B if A is a subclass of B. The language may not be the same, but the concepts are.
    – varkor
    Jul 27 '20 at 12:37
  • "X is contravariant with respect to Y" means that more specific versions of X must have less specific versions of Y (or the other way around - not sure). But in this case we are not talking about more or less specific versions of X.
    – user253751
    Jul 27 '20 at 12:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.