Explicit or Implicit Declaration and Inference
For more details on this topic, see Type 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 type inference: The compiler draws conclusions about the types of variables based on how programmers use those variables. For example, given a function f(x, y) that adds x and y together, the compiler can infer that x and y must be numbers – since addition is only defined for numbers. Therefore, any call to f 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 3.14 might imply a type of floating-point, while might imply a list of integers – typically an array.
Type inference is in general possible, if it is decidable 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 Hindley-Milner, is a restriction of System Fω 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.)
Read more about this topic: Type System
Famous quotes containing the words explicit, implicit, declaration and/or inference:
“Like dreaming, reading performs the prodigious task of carrying us off to other worlds. But reading is not dreaming because books, unlike dreams, are subject to our will: they envelop us in alternative realities only because we give them explicit permission to do so. Books are the dreams we would most like to have, and, like dreams, they have the power to change consciousness, turning sadness to laughter and anxious introspection to the relaxed contemplation of some other time and place.”
—Victor Null, South African educator, psychologist. Lost in a Book: The Psychology of Reading for Pleasure, introduction, Yale University Press (1988)
“The true colour of life is the colour of the body, the colour of the covered red, the implicit and not explicit red of the living heart and the pulses. It is the modest colour of the unpublished blood.”
—Alice Meynell (18471922)
“I foresee the time when the painter will paint that scene, no longer going to Rome for a subject; the poet will sing it; the historian record it; and, with the Landing of the Pilgrims and the Declaration of Independence, it will be the ornament of some future national gallery, when at least the present form of slavery shall be no more here. We shall then be at liberty to weep for Captain Brown. Then, and not till then, we will take our revenge.”
—Henry David Thoreau (18171862)
“I have heard that whoever loves is in no condition old. I have heard that whenever the name of man is spoken, the doctrine of immortality is announced; it cleaves to his constitution. The mode of it baffles our wit, and no whisper comes to us from the other side. But the inference from the working of intellect, hiving knowledge, hiving skill,at the end of life just ready to be born,affirms the inspirations of affection and of the moral sentiment.”
—Ralph Waldo Emerson (18031882)