-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a bottom type to IDL #476
Conversation
the need for a bottom type follows from: 1. We have `None` in ActorScript. 2. We want to use it in the IDL (@matthewhammer uses a generic `Result<t1,t2>` type, and if there cannot be an error, puts `None` in `t2`). So `None ∈ dom e`. 3. `None <: t` for all `t` in ActorScript 4. `∀ t1 t2 : dom(e), t1 <: t2 ⟹ e(t1) <: e(t2)` as per #465 This PR proposes adding a bottom type (called `absent`, but other names like `bottom` are fine too). But there are alternatives: * The ADL-AS spec currently has `e(None) = variant {}`. This has the right semantics as an empty set of values, but lacks the right subtyping relation in the IDL subtyping. We could fix the latter, i.e. add an ad-hoc rule `variant {} <: t` and would not have to extend the grammer of the IDL spec. I actually like that. * We define `e` to normalize types with `None` first, with rewrite rules like ``` (None, t) = None shared { n:None, … } = None variant { n:None, … } = variant { … } ? None = null [None] = () None -> t = unavailable t -> None = None // fishy, the function could just be not returning, // but still do something useful ``` with such rules I assume we can completely remove `None` from the actor signature (unless the whole actor becomes `None`). But this might be surprising to the user and cause problems if we add parametric type definitions at some point, such as ``` type Result<t1,t2> = { #ok : t1; #fail : t2 } ```
I understand reason 4, but I'm puzzled about reason 3. @matthewhammer, what's the point of using Not sure |
You mean you are puzzled about 2, right?
The point, I think, is that all functions return in a If we can decide that we don’t need 2, then we can simply not have |
Hm, I don't see any interesting combinators being used in the code, not even |
But even disregarding the actual case of produce exchange, do we want to support something like
where the developer is working with some library-provided parametric type It’s a bit of an odd case, but not completely unrealistic. Any other arguments in favor or against including a bottom type? |
I don't have a strong opinion, my only concern is that most languages do not have anything obvious to map it to, which means that we may be simplifying the life for AS for the price of making everybody else's harder. Thoughts? |
Don't most seriously typed languages have an empty type of some sort? Also, we do have an empty type already in the IDL ( For untyped languages like JS, it doesn’t really matter, because we never encounter values of type I don’t feel strongly either, but we have to either
(I am leaning towards 2: Doesn’t affect other languages, doesn’t complicate the grammar, but still allows AS developers to use |
Not so sure. In fact, I can't think of any outside the wider FP camp (to which I count Scala). More importantly, an empty type is not the same as a bottom type. On the other hand, other langs don't have variants either, which I suppose is similar to your point.
For the record, that would be far too hacky for my taste. Empty variant =/= bottom, empty record =/= top. Type isomorphism is not equivalence -- until we have an IDL based on Homotopy Type Theory. |
the need for a bottom type follows from:
We have
None
in ActorScript.We want to use it in the IDL (@matthewhammer uses a generic
Result<t1,t2>
type, and if there cannot be an error, putsNone
int2
). SoNone ∈ dom e
.None <: t
for allt
in ActorScript∀ t1 t2 : dom(e), t1 <: t2 ⟹ e(t1) <: e(t2)
as per IDL-AS mapping spec #465This PR proposes adding a bottom type (called
absent
, but other nameslike
bottom
are fine too). But there are alternatives:The ADL-AS spec currently has
e(None) = variant {}
. This has theright semantics as an empty set of values, but lacks the right
subtyping relation in the IDL subtyping. We could fix the latter,
i.e. add an ad-hoc rule
variant {} <: t
and would not have toextend the grammer of the IDL spec.
I actually like that.
We define
e
to normalize types withNone
first, with rewriterules like
with such rules I assume we can completely remove
None
from theactor signature (unless the whole actor becomes
None
).But this might be surprising to the user and cause problems if
we add parametric type definitions at some point, such as