Exobiont Systems

⌂ Home

(In-)Coherence under Transitivity of Coercive Subtyping

While coercions improve ergonomics, the freedom to add them introduces the risk of inconsistency. In particular, multiple coercion paths between the same two types may produce different results. Example 6. Suppose we have the following coercions, which would prove quite useful for pretty printing and serialization:

Then a value of type Radians can be converted to String along two different paths:

These may yield different string outputs (e.g. depending on whether the intermediate repre- sentation is degrees or reals), which breaks consistency.

Quite similarly, we might be tempted to define specialized coercions for

Obviously, in the presence of transitivity such type hierarchies will collapse under inconsistencies.

A coercion system is considered or consistent (or coherent) if, for any given source type σ and target type τ, all valid coercion paths from σ to τ are uniquely defined, i.e. they produce the same result for the same value. Coherence thus guarantees predictability and prevents semantic ambiguity.

Related

Compatibility via Conversion (Coercive Subtyping)

Implicit type conversion functions, also known as coercions, provide an alternative approach to implement subtyping. Instead of interpreting subtyping as set inclusion (where the...

Safe Coercions in Haskell

Some languages such as Haskell take a cautious approach: they restrict coercions to representationally equal types. This is supported by the...