Define a subtyping
relationship <:.
Type T1 is a subtype of T2 is denoted as T1 <: T2 or, in MeTTa
format
(<: T1 T2)
The subtyping relationship is:
- Reflexive:
⊢ T <: T - Transitive:
T1 <: T2 T2 <: T3 ⊢ T1 <: T3 - Contravariant over inputs and covariant over outputs:
T1 <: S1 S2 <: T2 ⊢ S1 -> S2 <: T1 -> T2
There are two variants of relationship between subtyping and type, one using explicit coercion, the other using implicit coercion.
For explicit coercion, the inference rule is the coercion function
itself, see coerce defined in rule-base.metta.
Because MeTTa supports non-determinism we can also do implicit type
coercion. In that case the typing relationship is treated itself as
type, and its witness is an inference rule, not a coercion function,
see STImplCoer defined in rule-base.metta.
From that experiment we can conclude the following:
- Subtyping is possible with MeTTa.
- Explicit coercion allows to treat programs (in that case coercion functions) on the same level as proofs, in a Curry-Howard correspondence fashion.
- Implicit coercion has the advantage of not requiring a coercion function, but does not treat functions on the same level as proofs.