Type signature

From Wikipedia, the free encyclopedia

Type signature is a term that is used in computer programming.

A type signature defines the inputs and outputs for a function or method. A type signature includes at least the function name and the number of its parameters. In some programming languages, it may also specify the function's return type or the types of its parameters.

Contents

[edit] Haskell

A type signature in the Haskell programming language is written, generally, in the following format:

functionName :: arg1Type -> arg2Type -> ... -> argNType

Notice that the final output can be regarded as an argument. This is a consequence of currying. That is, given a function that had one argument supplied, but takes in two inputs, the function is "curried" and becomes a function of one argument -- the one that is not supplied.

The actual type specifications can consist of an actual type, such as Integer, or a general type variable that is used in parametric polymorphic functions, such as "a", or "b", or "anyType". So we can write something like:

functionName :: a -> a -> ... -> a

Since Haskell supports higher-order functions, functions can be passed as arguments. This is written as:

functionName :: (a -> a) -> a

This function takes in a function with type signature a -> a, and returns data of type "a" out.

[edit] Java

In the Java virtual machine, internal type signatures are used to identify methods and classes at the level of the virtual machine code.

Example: The method String String.substring(int, int) is represented as java/lang/String/substring(II)Ljava/lang/String;

[edit] C

In C, declaration reflects use; thus a function pointer that would be invoked as

char c;
double d;
int retVal = (*fPtr)(c, d);

has the signature

int (*fPtr)(char c, double d);

[edit] See also

Languages