Home

subtyper

Subtyper is a term used in type theory and programming to describe the relationship that makes one type a subtype of another. In a subtyping relation, a type A is a subtype of type B if every value of A can be used wherever a value of B is expected, without causing type errors. The relation is typically denoted A <: B and is defined to be reflexive (A <: A) and transitive (if A <: B and B <: C, then A <: C).

Subtyping arises from the need to reason about polymorphism and code reuse. It enables upcasting, where a

Key aspects of subtyping include variance in generic types. For function types, parameters are contravariant and

Common examples include class hierarchies in object-oriented languages (Dog is a subtype of Animal) and, with

Subtyping is enforced by a language’s type system or a dedicated subtyping checker, ensuring type safety while

value
of
a
more
specific
type
is
treated
as
a
value
of
a
more
general
type,
and
supports
safe
substitution
in
programs.
Subtyping
can
be
nominal,
where
the
relation
is
declared
by
explicit
inheritance
or
interface
implementation,
or
structural,
where
the
relation
is
determined
by
the
shape
of
the
types’
members.
return
types
are
covariant:
a
function
that
accepts
a
more
general
parameter
type
and
returns
a
more
specific
type
can
be
a
subtype
of
another
function
type,
under
certain
rules.
For
container
types,
variance
(covariant,
contravariant,
or
invariant)
determines
whether
a
container
of
one
type
can
be
substituted
for
a
container
of
another.
varying
rules,
generic
collections
(e.g.,
List<Dog>
versus
List<Animal>).
enabling
flexible
and
reusable
code.
See
also
type
system,
variance,
covariance,
contravariance,
and
polymorphism.