World Library  
Flag as Inappropriate
Email this Article

Type system

Article Id: WHEBN0000199701
Reproduction Date:

Title: Type system  
Author: World Heritage Encyclopedia
Language: English
Subject: Programming language, Nominal type system, Mirah (programming language), Io (programming language), SWLPC
Collection: Data Types, Program Analysis, Type Systems, Type Theory
Publisher: World Heritage Encyclopedia

Type system

In programming languages, a type system is a collection of rules that assign a property called a type to the various constructs—such as variables, expressions, functions or modules— that a computer program is composed of.[1] The main purpose of a type system is to reduce bugs in computer programs[2] by defining interfaces between different parts of a computer program, and then checking that the parts have been connected in a consistent way. This checking can happen statically (at compile time), dynamically (at run time), or it can happen as a combination of static and dynamic checking. Type systems have other purposes as well, such as enabling certain compiler optimizations, allowing for multiple dispatch, providing a form of documentation, etc.

An example of a simple type system is that of the C language. The portions of a C program are the function definitions. One function is invoked by another function. The interface of a function states the name of the function and a list of values that are passed to the function's code. The code of an invoking function states the name of the invoked, along with the names of variables that hold values to pass to it. During execution, the values are placed into temporary storage, then execution jumps to the code of the invoked function. The invoked function's code accesses the values and makes use of them. If the instructions inside the function are written with the assumption of receiving an integer value, but the calling code passed a floating-point value, then the wrong result will be computed by the invoked function. The C compiler checks the type declared for each variable sent, against the type declared for each variable in the interface of the invoked function. If the types do not match, the compiler throws a compile-time error.

In greater technical depth, a type-system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur. The particular type system in question determines exactly what constitutes a type error, but in general the aim is to prevent operations expecting a certain kind of value from being used with values for which that operation does not make sense (logic errors); memory errors will also be prevented. Type systems are often specified as part of programming languages, and built into the interpreters and compilers for them; although the type system of a language can be extended by optional tools that perform additional kinds of checks using the language's original type syntax and grammar.

A compiler may also use the static type of a value to optimize the storage it needs and the choice of algorithms for operations on the value. In many C compilers the float data type, for example, is represented in 32 bits, in accord with the IEEE specification for single-precision floating point numbers. They will thus use floating-point-specific microprocessor operations on those values (floating-point addition, multiplication, etc.).

The depth of type constraints and the manner of their evaluation affect the typing of the language. A programming language may further associate an operation with varying concrete algorithms on each type in the case of type polymorphism. Type theory is the study of type systems, although the concrete type systems of programming languages originate from practical issues of computer architecture, compiler implementation, and language design.


Formally, type theory studies type systems. A programming language must have occurrence to type check using the type system whether at compiler time or runtime, manually annotated or automatically inferred. As Mark Manasse concisely put it:[3]

The fundamental problem addressed by a type theory is to ensure that programs have meaning. The fundamental problem caused by a type theory is that meaningful programs may not have meanings ascribed to them. The quest for richer type systems results from this tension.

Assigning a data type, what is called typing, gives meaning to a sequences of bits such as a value in memory or some object such as a variable. The hardware of a general purpose computer is unable to discriminate between for example a memory address and an instruction code, or between a character, an integer, or a floating-point number, because it makes no intrinsic distinction between any of the possible values that a sequence of bits might mean. Associating a sequence of bits with a type conveys that meaning to the programmable hardware to form a symbolic system composed of that hardware and some program. A program associates each value with at least one particular type, but it also can occur that one value is associated with many subtypes. Other entities, such as objects, modules, communication channels, dependencies can become associated with a type. Even a type can become associated with a type. An implementation of some type system could in theory associate some identifications named this way:

These are the kinds of abstractions typing can go through on a hierarchy of levels contained in a system.

When a programming language evolves a more elaborate type system, it gains a more finely grained rule set than basic type checking, but this comes at a price when the type inferences (and other properties) become undecidable, and when more attention must be paid by the programmer to annotate code or to consider computer-related operations and functioning. It is challenging to find a sufficiently expressive type system that satisfies all programming practices in a type safe manner.

The more type restrictions that are imposed by the compiler, the more strongly typed a programming language is. Strongly typed languages often require the programmer to make explicit conversions in contexts where an implicit conversion would cause no harm. Pascal's type system has been described as "too strong" because, for example, the size of an array or string is part of its type, making some programming tasks difficult.[4][5] Haskell is also strongly typed but its types are automatically inferred so that explicit conversions are unnecessary.

A programming language compiler can also implement a dependent type or an effect system, which enables even more program specifications to be verified by a type checker. Beyond simple value-type pairs, a virtual "region" of code is associated with an "effect" component describing what is being done with what, and enabling for example to "throw" an error report. Thus the symbolic system may be a type and effect system, which endows it with more safety checking than type checking alone. Whether automated by the compiler or specified by a programmer, a type system makes program behavior illegal that is outside the type-system rules. Advantages provided by programmer-specified type systems include:

  • Abstraction (or modularity) – Types enable programmers to think at a higher level than the bit or byte, not bothering with low-level implementation. For example, programmers can begin to think of a string as a collection of character values instead of as a mere array of bytes. Higher still, types enable programmers to think about and express interfaces between two of any-sized subsystems. This enables more levels of localization so that the definitions required for interoperability of the subsystems remain consistent when those two subsystems communicate.
  • Documentation – In more expressive type systems, types can serve as a form of documentation clarifying the intent of the programmer. For instance, if a programmer declares a function as returning a timestamp type, this documents the function when the timestamp type can be explicitly declared deeper in the code to be integer type.

Advantages provided by compiler-specified type systems include:

  • Optimization – Static type-checking may provide useful compile-time information. For example, if a type requires that a value must align in memory at a multiple of four bytes, the compiler may be able to use more efficient machine instructions.
  • Safety – A type system enables the compiler to detect meaningless or probably invalid code. For example, we can identify an expression 3 / "Hello, World" as invalid, when the rules do not specify how to divide an integer by a string. Strong typing offers more safety, but cannot guarantee complete type safety.

Type safety contributes to program correctness, but can only guarantee correctness at the expense of making the type checking itself an undecidable problem. In a type system with automated type checking a program may prove to run incorrectly yet be safely typed, and produce no compiler errors. Division by zero is an unsafe and incorrect operation, but a type checker running only at compile time doesn't scan for division by zero in most programming languages, and then it is left as a runtime error. To prove the absence of these more-general-than-types defects, other kinds of formal methods, collectively known as program analyses, are in common use. Alternatively, a sufficiently expressive type system, such as in dependently typed languages, can prevent these kinds of errors (for example, expressing "the type of non-zero numbers"). In addition software testing is an empirical method for finding errors that the type checker cannot detect.

Type checking

The process of verifying and enforcing the constraints of types – type checking – may occur either at compile-time (a static check) or run-time (a dynamic check). If a language specification requires its typing rules strongly (i.e., more or less allowing only those automatic type conversions that do not lose information), one can refer to the process as strongly typed, if not, as weakly typed. The terms are not usually used in a strict sense.

Static type-checking

Static type-checking is the process of verifying the type safety of a program based on analysis of a program's text (source code). If a program passes a static type-checker, then the program is guaranteed to satisfy some set of type-safety properties for all possible inputs.

Because static type-checking operates on a program's text, it allows many bugs to be caught early in the development cycle.

Static type-checking can be thought of as a limited form of program verification (see type safety). In a type-safe language, static type-checking can also be thought of as an optimization. If a compiler can prove that a program is well-typed, then it does not need to emit dynamic safety checks, allowing the resulting compiled binary to run faster.

Static type-checking for Turing-complete languages is inherently conservative. That is, if a type system is both sound (meaning that it rejects all incorrect programs) and decidable (meaning that it is possible to write an algorithm which determines whether a program is well-typed), then it will always be possible to define a program which is well-typed but which does not satisfy the type-checker.[6] For example, consider a program containing the code:

if then else Even if the expression always evaluates to true at run-time, most type-checkers will reject the program as ill-typed, because it is difficult (if not impossible) for a static analyzer to determine that the else branch will not be taken. Conversely, a static type-checker will quickly detect type errors in rarely used code paths. Without static type checking, even tests with 100% coverage may be unable to find such type errors. The tests may fail to detect such type errors, because the combination of all places where values are created and all places where a certain value is used must be taken into account. A number of useful and common programming language features cannot be checked statically, such as . Therefore, many languages will have both static and dynamic type-checking; the static type-checker verifies what it can, and dynamic checks verify the rest. Many languages with static type-checking provide a way to bypass the type checker. Some languages allow programmers to choose between static and dynamic type safety. For example, distinguishes between "statically-typed" and "dynamically-typed" variables; uses of the former are checked statically, while uses of the latter are checked dynamically. Other languages allow users to write code which is not type-safe. For example, in , programmers can freely cast a value between any two types which have the same size. For a list of languages with static type-checking, see . === Dynamic type-checking and runtime type information === Dynamic type-checking is the process of verifying the type safety of a program at runtime. Implementations of dynamically type-checked languages generally associate each runtime object with a "type tag" (i.e., a reference to a type) containing its type information. This runtime type information (RTTI) can also be used to implement , , , , and similar features. Most type-safe languages include some form of dynamic type-checking, even if they also have a static type checker. The reason for this is that many useful features or properties are difficult or impossible to verify statically. For example, suppose that a program defines two types, A and B, where B is a subtype of A. If the program tries to convert a value of type A to type B, then the operation is legal only if the value being converted is actually a value of type B. Therefore, a dynamic check is needed to verify that the operation is safe. By definition, dynamic type-checking may cause a program to fail at runtime. In some programming languages, it is possible to anticipate and recover from these failures. In others, type-checking errors are considered fatal. Programming languages which include dynamic type-checking but not static type-checking are often called "dynamically-typed programming languages". For a list of such languages, see . ===Combining static and dynamic type-checking=== The presence of static type-checking in a programming language does not necessarily imply the absence of dynamic type-checking. For example, Java and some other ostensibly statically typed languages support types to their , querying an object to discover its dynamic type and other type operations that depend on runtime type information. More generally, most programming languages include mechanisms for dispatching over different 'kinds' of data, such as s, , and s. Even when not interacting with type annotations or type checking, such mechanisms are materially similar to dynamic typing implementations. See for more discussion of the interactions between static and dynamic typing. Objects in object oriented languages are usually accessed by a reference whose static target type (or manifest type) is equal to either the object's run-time type (its latent type) or a supertype thereof. This is conformant with the , which states that all operations performed on an instance of a given type can also be performed on an instance of a subtype. This concept is also known as subsumption. In some languages subtypes may also possess return types and argument types respectively. Certain languages, for example , , or , are dynamically type-checked by default, but allow programs to opt into static type-checking by providing optional annotations. One reason to use such hints would be to optimize the performance of critical sections of a program. As of version 4.0, the C# language provides a way to indicate that a variable should not be statically type-checked. A variable whose type is dynamic will not be subject to static type-checking. Instead, the program relies on runtime type information to determine how the variable may be used.|publisher=Microsoft|accessdate=14 January 2014}} ===Static and dynamic type checking in practice=== The choice between static and dynamic typing requires s. Static typing can find type errors reliably at compile time. This should increase the reliability of the delivered program. However, programmers disagree over how commonly type errors occur, and thus disagree over the proportion of those bugs that are coded that would be caught by appropriately representing the designed types in code. Static typing advocates believe programs are more reliable when they have been well type-checked, while dynamic typing advocates point to distributed code that has proven reliable and to small bug databases. The value of static typing, then, presumably increases as the strength of the type system is increased. Advocates of such as and have suggested that almost all bugs can be considered type errors, if the types used in a program are properly declared by the programmer or correctly inferred by the compiler. }} Static typing usually results in compiled code that executes more quickly. When the compiler knows the exact data types that are in use, it can produce optimized machine code. Further, compilers for statically typed languages can find assembler shortcuts more easily. Some dynamically typed languages such as allow optional type declarations for optimization for this very reason. Static typing makes this pervasive. See . By contrast, dynamic typing may allow compilers to run more quickly and allow to dynamically load new code, since changes to source code in dynamically typed languages may result in less checking to perform and less code to revisit. This too may reduce the edit-compile-test-debug cycle. Statically typed languages that lack (such as C and Java) require that programmers declare the types they intend a method or function to use. This can serve as additional documentation for the program, which the compiler will not permit the programmer to ignore or permit to drift out of synchronization. However, a language can be statically typed without requiring type declarations (examples include , , , and to a lesser extent and ), so explicit type declaration is not a necessary requirement for static typing in all languages. Dynamic typing allows constructs that some static type checking would reject as illegal. For example, '''' functions, which execute arbitrary data as code, become possible. An ''eval'' function is possible with static typing, but requires advanced uses of . Furthermore, dynamic typing better accommodates transitional code and prototyping, such as allowing a placeholder data structure () to be transparently used in place of a full-fledged data structure (usually for the purposes of experimentation and testing). Dynamic typing typically allows (which enables ). Many languages with static typing also feature or other mechanisms like which also enables easier code reuse. Dynamic typing typically makes easier to use. For example, are typically more cumbersome to write than the equivalent or code. More advanced run-time constructs such as es and are often more difficult to use in statically typed languages. In some languages, such features may also be used e.g. to generate new types and behaviors on the fly, based on run-time data. Such advanced constructs are often provided by s; many of these are dynamically typed, although ''dynamic typing'' need not be related to ''dynamic programming languages''. ==="Strong" and "weak" type systems=== Languages are often colloquially referred to as "strongly typed" or "weakly typed". In fact, there is no universally accepted definition of what these terms mean. In general, there are more precise terms to represent the differences between type systems that lead people to call them "strong" or "weak". ===Type safety and memory safety === A third way of categorizing the type system of a programming language uses the safety of typed operations and conversions. Computer scientists consider a language "type-safe" if it does not allow operations or conversions that violate the rules of the type system. Some observers use the term ''memory-safe language'' (or just ''safe language'') to describe languages that do not allow programs to access memory that has not been assigned for their use. For example, a memory-safe language will , or else statically guarantee (i.e., at compile time before execution) that array accesses out of the array boundaries will cause compile-time and perhaps runtime errors. Consider the following program of a language that is both type-safe and memory-safe: is an example of a language that is both type-safe and memory-safe. var x := 5; var y := "37"; var z := x + y; In this example, the variable will have the value 42. While this may not be what the programmer anticipated, it is a well-defined result. If was a different string, one that could not be converted to a number (e.g. "Hello World"), the result would be well-defined as well. Note that a program can be type-safe or memory-safe and still crash on an invalid operation; in fact, if a program encounters an operation which is not type-safe, terminating the program is often the only option. Now consider a similar example in C: int x = 5; char y[] = "37"; char* z = x + y; In this example will point to a memory address five characters beyond , equivalent to three characters after the terminating zero character of the string pointed to by . This is memory that the program is not expected to access. It may contain garbage data, and it certainly doesn't contain anything useful. As this example shows, C is neither a memory-safe nor a type-safe language. In general, type-safety and memory-safety go hand in hand. For example, a language which supports pointer arithmetic and number-to-pointer conversions (like C) is neither memory-safe nor type-safe, since it allows arbitrary memory to be accessed as if it were valid memory of any type. For more information, see . ===Variable levels of type checking=== Some languages allow different levels of checking to apply to different regions of code. Examples include:- * The use strict directive in [ Standard ECMA-262]. Retrieved on 2013-07-17.[ Strict mode - JavaScript | MDN]. (2013-07-03). Retrieved on 2013-07-17.[ Strict Mode (JavaScript)]. Retrieved on 2013-07-17. and applies stronger checking. * The @ operator in suppresses some error messages. * The Option Strict On in allows the compiler to require a conversion between objects. Additional tools such as and can also be used to achieve a higher level of strictness. ===Optional type systems=== It has been proposed, chiefly by , that the choice of type system be made independent of choice of language; that a type system should be a module that can be "plugged" into a language as required. He believes this is advantageous, because what he calls mandatory type systems make languages less expressive and code more fragile.[ Bracha, G.: ''Pluggable Types''] The requirement that types do not affect the semantics of the language is difficult to fulfill; for instance, class-based inheritance becomes impossible. Optional typing is related to , but still distinct from it. ==Polymorphism and types== The term "polymorphism" refers to the ability of code (in particular, methods or classes) to act on values of multiple types, or to the ability of different instances of the same data structure to contain elements of different types. Type systems that allow polymorphism generally do so in order to improve the potential for code re-use: in a language with polymorphism, programmers need only implement a data structure such as a list or an once, rather than once for each type of element with which they plan to use it. For this reason computer scientists sometimes call the use of certain forms of polymorphism ''''. The type-theoretic foundations of polymorphism are closely related to those of , and (in some cases) . ===Duck typing=== In "duck typing", a statement calling a m on an object does not rely on the declared type of the object; only that the object, of whatever type, must supply an implementation of the method called, when called, at run-time. Duck typing differs from in that, if the "part" (of the whole module structure) needed for a given local computation is present ''at runtime'', the duck type system is satisfied in its type identity analysis. On the other hand, a structural type system would require the analysis of the whole module structure at compile time to determine type identity or type dependence. Duck typing differs from a in a number of aspects. The most prominent ones are that for duck typing, type information is determined at runtime (as contrasted to compile time), and the name of the type is irrelevant to determine type identity or type dependence; only partial structure information is required for that for a given point in the program execution. Duck typing uses the premise that (referring to a value) "if it walks like a duck, and quacks like a duck, then it is a duck" (this is a reference to the that is attributed to ). The term may have been coined by in a 2000 message to the comp.lang.python (see ). While one controlled experiment showed an increase in developer productivity for duck typing in single developer projects,Stefan Hanenberg. ”An experiment about static and dynamic type systems: doubts about the positive impact of static type systems on development time“. OOPSLA 2010. other controlled experiments on API usability show the opposite.Kleinschmager, Hanenberg, Robbes, Tanter, Stefik: Do static type systems improve the maintainability of software systems? An empirical study. ICPC 2012Hanenberg, Kleinschmager, S.Robbes, R.Tanter, Stefik: An empirical study on the impact of static typing on software maintainability, ESE 2014 ==Specialized type systems== Many type systems have been created that are specialized for use in certain environments with certain types of data, or for out-of-band . Frequently, these are based on ideas from formal and are only available as part of prototype research systems. ===Dependent types=== s are based on the idea of using scalars or values to more precisely describe the type of some other value. For example, matrix(3, 3) might be the type of a 3×3 matrix. We can then define typing rules such as the following rule for matrix multiplication: matrix_{multiply} : matrix(k, m) \times matrix(m, n) \to matrix(k, n) where k, m, n are arbitrary positive integer values. A variant of called has been created based on this type system, but because type checking for conventional dependent types is , not all programs using them can be type-checked without some kind of limits. Dependent ML limits the sort of equality it can decide to . Other languages such as make the value of all expressions in the language decidable so that type checking can be decidable. However, in general , so many programs require hand-written annotations, which may be very non-trivial. As this impedes the development process many language implementations provide an easy way out in the form of an option to disable this condition. This, however, comes at the cost of making the type-checker run in an when fed programs that don't type-check, causing the compiler to hang. ===Linear types=== s, based on the theory of , and closely related to s, are types assigned to values having the property that they have one and only one reference to them at all times. These are valuable for describing large s such as files, strings, and so on, because any operation that simultaneously destroys a linear object and creates a similar object (such as 'str = str + "a"') can be optimized "under the hood" into an in-place mutation. Normally this is not possible, as such mutations could cause side effects on parts of the program holding other references to the object, violating . They are also used in the prototype operating system for interprocess communication, statically ensuring that processes cannot share objects in shared memory in order to prevent race conditions. The language (a -like language) uses this type system in order to gain a lot of speed (compared to performing a deep copy) while remaining safe. ===Intersection types=== s are types describing values that belong to ''both'' of two other given types with overlapping value sets. For example, in most implementations of C the signed char has range -128 to 127 and the unsigned char has range 0 to 255, so the intersection type of these two types would have range 0 to 127. Such an intersection type could be safely passed into functions expecting ''either'' signed or unsigned chars, because it is compatible with both types. Intersection types are useful for describing overloaded function types: For example, if " → " is the type of functions taking an integer argument and returning an integer, and " → " is the type of functions taking a float argument and returning a float, then the intersection of these two types can be used to describe functions that do one or the other, based on what type of input they are given. Such a function could be passed into another function expecting an " → " function safely; it simply would not use the " → " functionality. In a subclassing hierarchy, the intersection of a type and an ancestor type (such as its parent) is the most derived type. The intersection of sibling types is empty. The Forsythe language includes a general implementation of intersection types. A restricted form is s. ===Union types=== s are types describing values that belong to ''either'' of two types. For example, in C, the signed char has range -128 to 127, and the unsigned char has range 0 to 255, so the union of these two types would have range -128 to 255. Any function handling this union type would have to deal with integers in this complete range. More generally, the only valid operations on a union type are operations that are valid on ''both'' types being unioned. C's "union" concept is similar to union types, but is not typesafe, as it permits operations that are valid on ''either'' type, rather than ''both''. Union types are important in program analysis, where they are used to represent symbolic values whose exact nature (e.g., value or type) is not known. In a subclassing hierarchy, the union of a type and an ancestor type (such as its parent) is the ancestor type. The union of sibling types is a subtype of their common ancestor (that is, all operations permitted on their common ancestor are permitted on the union type, but they may also have other valid operations in common). ===Existential types=== types are frequently used in connection with s to represent s and s, due to their ability to separate implementation from interface. For example, the type "T = ∃X { a: X; f: (X → int); }" describes a module interface that has a data member named ''a'' of type ''X'' and a function named ''f'' that takes a parameter of the ''same'' type ''X'' and returns an integer. This could be implemented in different ways; for example: * intT = { a: int; f: (int → int); } * floatT = { a: float; f: (float → int); } These types are both subtypes of the more general existential type T and correspond to concrete implementation types, so any value of one of these types is a value of type T. Given a value "t" of type "T", we know that "t.f(t.a)" is well-typed, regardless of what the abstract type ''X'' is. This gives flexibility for choosing types suited to a particular implementation while clients that use only values of the interface type—the existential type—are isolated from these choices. In general it's impossible for the typechecker to infer which existential type a given module belongs to. In the above example intT { a: int; f: (int → int); } could also have the type ∃X { a: X; f: (int → int); }. The simplest solution is to annotate every module with its intended type, e.g.: * intT = { a: int; f: (int → int); } '''as''' ∃X { a: X; f: (X → int); } Although abstract data types and modules had been implemented in programming languages for quite some time, it wasn't until 1988 that and established the formal theory under the slogan: "Abstract [data] types have existential type".Mitchell, John C.; Plotkin, Gordon D.; [ ''Abstract Types Have Existential Type''], ACM Transactions on Programming Languages and Systems, Vol. 10, No. 3, July 1988, pp. 470–502 The theory is a second-order similar to , but with existential instead of universal quantification. ==Explicit or implicit declaration and inference== Many static type systems, such as those of C and Java, require ''type declarations'': The programmer must explicitly associate each variable with a particular type. Others, such as Haskell's, perform '''': The compiler draws conclusions about the types of variables based on how programmers use those variables. For example, given a function that adds and together, the compiler can infer that and must be numbers – since addition is only defined for numbers. Therefore, any call to elsewhere in the program that specifies a non-numeric type (such as a string or list) as an argument would signal an error. Numerical and string constants and expressions in code can and often do imply type in a particular context. For example, an expression might imply a type of , while } might imply a list of integers – typically an . Type inference is in general possible, if it is in the type theory in question. Moreover, even if inference is undecidable in general for a given type theory, inference is often possible for a large subset of real-world programs. Haskell's type system, a version of , is a restriction of to so-called rank-1 polymorphic types, in which type inference is decidable. Most Haskell compilers allow arbitrary-rank polymorphism as an extension, but this makes type inference undecidable. (Type checking is decidable, however, and rank-1 programs still have type inference; higher rank polymorphic programs are rejected unless given explicit type annotations.) ==Types of types== A ''type of types'' is a . Kinds appear explicitly in , such as a ''type constructor'' in the language. Types fall into several broad categories: * s – the simplest kind of type; e.g., and ** ** s – types of whole numbers; e.g., integers and natural numbers ** s – types of numbers in representation * s * s ** s * s – types composed of basic types; e.g., or . *:s * * * * s; e.g., * * * s; e.g., binary functions * types, such as parameterized types * types, such as * s – types that identify subsets of other types * s – types that depend on terms (values) * s – types that describe or constrain the structure of object-oriented systems * Pre-defined types provided for convenience in real-world applications, such as date, time and money. ==Unified type system== Some languages like have a unified type system.[ Standard ECMA-334], 8.2.4 Type system unification. This means that all types including primitive types inherit from a single root object. Every type in inherits from the Object class. has several primitive types that are not objects. Java provides wrapper object types that exist together with the primitive types so developers can use either the wrapper object types or the simpler non-object primitive types. ==Compatibility: equivalence and subtyping== A type-checker for a statically typed language must verify that the type of any is consistent with the type expected by the context in which that expression appears. For instance, in an of the form x := ''e'', the inferred type of the expression ''e'' must be consistent with the declared or inferred type of the variable x. This notion of consistency, called ''compatibility'', is specific to each programming language. If the type of ''e'' and the type of x are the same and assignment is allowed for that type, then this is a valid expression. In the simplest type systems, therefore, the question of whether two types are compatible reduces to that of whether they are ''equal'' (or ''equivalent''). Different languages, however, have different criteria for when two type expressions are understood to denote the same type. These different ''equational theories'' of types vary widely, two extreme cases being ''s'', in which any two types that describe values with the same structure are equivalent, and ''s'', in which no two syntactically distinct type expressions denote the same type (''i.e.'', types must have the same "name" in order to be equal). In languages with , the compatibility relation is more complex. In particular, if A is a subtype of B, then a value of type A can be used in a context where one of type B is expected, even if the reverse is not true. Like equivalence, the subtype relation is defined differently for each programming language, with many variations possible. The presence of parametric or ad hoc in a language may also have implications for type compatibility. ==Programming style== Some programmers prefer statically typed languages; others prefer dynamically typed languages. Statically typed languages alert programmers to type errors during compilation, and they may perform better at runtime. Likewise, there is no need to manually declare all types in statically typed languages with type inference; thus, the need for the programmer to explicitly specify types of variables is automatically lowered for such languages. Advocates of dynamically typed languages claim they better support rapid prototyping and that type errors are only a small subset of errors in a program. Corporation }} ==See also== * * * * * * * * * ==References== ==Further reading== * |date = December 1985| volume = 17|issue=4|issn = 0360-0300|pages = 471–523|doi = 10.1145/6041.6042|publisher = |location = New York, NY, USA | ref = harv}} * * * Tratt, Laurence, [ ''Dynamically Typed Languages''], Advances in Computers, Vol. 77, pp. 149–184, July 2009 ==External links== * Smith, Chris, [ ''What To Know Before Debating Type Systems'']

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.