About: Covariance and contravariance (computer science)     Goto   Sponge   NotDistinct   Permalink

An Entity of Type : owl:Thing, within Data Space : el.dbpedia.org associated with source document(s)

Many programming language type systems support subtyping. For instance, if the type Cat is a subtype of Animal, then an expression of type Cat should be substitutable wherever an expression of type Animal is used. On the other hand, "function from Animal to String" is a subtype of "function from Cat to String" because the function type constructor is contravariant in the parameter type. Here the subtyping relation of the simple types is reversed for the complex types.

AttributesValues
rdfs:label
  • Covariance and contravariance (computer science) (en)
rdfs:comment
  • Many programming language type systems support subtyping. For instance, if the type <span class="n">Cat</span> is a subtype of <span class="n">Animal</span>, then an expression of type <span class="n">Cat</span> should be substitutable wherever an expression of type <span class="n">Animal</span> is used. On the other hand, "function from Animal to String" is a subtype of "function from Cat to String" because the function type constructor is contravariant in the parameter type. Here the subtyping relation of the simple types is reversed for the complex types. (en)
sameAs
dbp:wikiPageUsesTemplate
Subject
Link from a Wikipage to an external page
thumbnail
foaf:depiction
  • http://commons.wikimedia.org/wiki/Special:FilePath/AnimalShelter.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_contravariant_argument.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_contravariant_argument_animalshelter.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_covariant_argument.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_covariant_argument_animalshelter.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_covariant_return.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_covariant_return_animalshelter.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Inheritance_invariant.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Java_wildcard_subtyping.svg
  • http://commons.wikimedia.org/wiki/Special:FilePath/Vererbung_T.svg
prov:wasDerivedFrom
Wikipage page ID
page length (characters) of wiki page
Wikipage revision ID
Link from a Wikipage to another Wikipage
has abstract
  • Many programming language type systems support subtyping. For instance, if the type <span class="n">Cat</span> is a subtype of <span class="n">Animal</span>, then an expression of type <span class="n">Cat</span> should be substitutable wherever an expression of type <span class="n">Animal</span> is used. Variance refers to how subtyping between more complex types relates to subtyping between their components. For example, how should a list of <span class="n">Cat</span>s relate to a list of <span class="n">Animal</span>s? Or how should a function that returns <span class="n">Cat</span> relate to a function that returns <span class="n">Animal</span>? Depending on the variance of the type constructor, the subtyping relation of the simple types may be either preserved, reversed, or ignored for the respective complex types. In the OCaml programming language, for example, "list of Cat" is a subtype of "list of Animal" because the list type constructor is covariant. This means that the subtyping relation of the simple types are preserved for the complex types. On the other hand, "function from Animal to String" is a subtype of "function from Cat to String" because the function type constructor is contravariant in the parameter type. Here the subtyping relation of the simple types is reversed for the complex types. A programming language designer will consider variance when devising typing rules for language features such as arrays, inheritance, and generic datatypes. By making type constructors covariant or contravariant instead of invariant, more programs will be accepted as well-typed. On the other hand, programmers often find contravariance unintuitive, and accurately tracking variance to avoid runtime type errors can lead to complex typing rules. In order to keep the type system simple and allow useful programs, a language may treat a type constructor as invariant even if it would be safe to consider it variant, or treat it as covariant even though that could violate type safety. (en)
foaf:isPrimaryTopicOf
is rdfs:seeAlso of
is Wikipage redirect of
Faceted Search & Find service v1.17_git151 as of Feb 20 2025


Alternative Linked Data Documents: ODE     Content Formats:   [cxml] [csv]     RDF   [text] [turtle] [ld+json] [rdf+json] [rdf+xml]     ODATA   [atom+xml] [odata+json]     Microdata   [microdata+json] [html]    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3240 as of Nov 11 2024, on Linux (x86_64-ubuntu_focal-linux-gnu), Single-Server Edition (72 GB total memory, 1 GB memory in use)
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2025 OpenLink Software