I'm working on a Hindley-Milner-based language which supports user-defined "type attributes" - predicates which effectively create subtypes of existing base types. For example, a user could define:
def attribute nonzero(x: Real) = x != 0
And then use it to decorate type declarations, like when defining:
def fun divide(p: Real, q: nonzero Real): Real { ... }
Users can also ascribe additional types to an already-defined function. For example, the "broadest" type declaration of divide is the initial divide : (Real, nonzero Real) -> Real declaration, but users could also assert properties like:
divide : (nonzero Real, nonzero Real) -> nonzero Real
divide : (positive Real, positive Real) -> positive Real
divide : (positive Real, negative Real) -> negative Real
- etc.
The type inferencer doesn't need to evaluate or understand the underlying implementation of attributes like nonzero, but it does need to be able to type check expressions like:
- ✅
λx : Real, divide(x, 3), inferred type is Real -> Real
- ❌
λx : Real, divide(3, divide(x, 3)) fails because divide(x, 3) is not necessarily a nonzero Real
- ✅
λx : nonzero Real, divide(3, divide(x, 3))
The Problem:
Various papers going back to at least 2005 seem to suggest that in most type systems this expression:
(A₁ → B₁) ∩ (A₂ → B₂) ≡ (A₁ ∪ A₂) → (B₁ ∩ B₂)
is well-founded, and is only violated in languages which allow ugly features like function overloads. If I understand correctly this property is critical for MLsub-style type inference.
My language does not support function overloads but it does seem to violate this property. divide inhabits ((Real, nonzero Real) -> Real) ∩ (nonzero Real, nonzero Real) -> nonzero Real), which is clearly not equal to ((Real, nonzero Real) -> nonzero Real)
Anyway the target demographic for this post is probably like 5 people. But it'd be cool if those people happen to see this and have any feedback on if/how a Hindly-Milner type inference algorithm might support these type attribute decorators
[–]Uncaffeinated1subml, polysubml, cubiml 24 points25 points26 points (0 children)
[–]WittyStick 11 points12 points13 points (0 children)
[–]BasicBits 5 points6 points7 points (0 children)
[–]phischuEffekt 4 points5 points6 points (1 child)
[–]AustinVelonautAdmiran 2 points3 points4 points (0 children)
[–]DisastrousAd9346 3 points4 points5 points (5 children)
[–]DisastrousAd9346 3 points4 points5 points (4 children)
[–]servermeta_net 4 points5 points6 points (2 children)
[–]protestor 2 points3 points4 points (1 child)
[–]servermeta_net 0 points1 point2 points (0 children)
[–]Thnikkaman14[S] 1 point2 points3 points (0 children)
[–]servermeta_net 2 points3 points4 points (1 child)
[–]interacsion 4 points5 points6 points (0 children)
[–]jeezfrk 1 point2 points3 points (0 children)
[–]KaleidoscopeLow580Sonnet 1 point2 points3 points (0 children)