Type signature
It has been suggested that [[::Method signature| Method signature ]] and [[::Signature (computer science)| Signature (computer science) ]] be merged into this article or section. (Discuss) |
In computer science, a type signature defines the inputs and outputs for a function, subroutine or method. A type signature includes at least the function name and the number of its arguments. In some programming languages, it may also specify the function's return type, the types of its arguments, or errors it may pass back.
Haskell
A type signature in the Haskell programming language is written, generally, in the following format:
functionName :: arg1Type -> arg2Type -> ... -> argNType
Notice that the type of the result can be regarded as everything past the first supplied argument. This is a consequence of currying, which is made possible by Haskell's support for first-class functions. That is, given a function that takes in two inputs, but had one argument supplied, the function is "curried" to produce a function of one argument—the one that is not supplied. Thus calling f(x), where f :: a -> b -> c, yields a new function f' :: b -> c which can be called f'(b) to produce c.
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.
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 Ljava/lang/String/substring(II)Ljava/lang/String;
C/C++
In C and C++ the type signature is declared by the most-commonly known function prototype. In C/C++, a function declaration reflects its use; for example, 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);
File:HelloWorld.svg | This programming language-related article is a stub. You can help Wikipedia by expanding it. |
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...
- Pages using deprecated source tags
- Pages with syntax highlighting errors
- Articles lacking sources from December 2009
- Articles with invalid date parameter in template
- All articles lacking sources
- Pages with broken file links
- Articles to be merged from May 2009
- All articles to be merged
- Programming language topics
- Type theory
- Computer programming
- Programming language topic stubs