-
Notifications
You must be signed in to change notification settings - Fork 90
Possible confusion between the unit type and the 0-tuple #21
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
Comments
Is there a reason unit and the zero tuple are not the same type in the component model? That seems more natural to me than making a zero tuple a validation error. That is, why have a separate unit type, rather than using zero tuples for that purpose? |
I think it's fine if a language bindings generator maps values of two distinct interface types ( (On a side note, #23 makes |
The original motivation for this issue is that Wasmtime, for core wasm, supports something like: let func: wasmtime::Func = ...;
let typed_func = func.typed::<(i32, i32), (f32, f64), _>(&store)?; where here For the component model I was hoping to implement something similar such as: let func: wasmtime::component::Func = ...;
let typed_func = func.typed::<(String, u8), Vec<String>, _>(&store)?; With this sort of type-based type assertions it's ambiguous when in Rust it's typed: let func: wasmtime::component::Func = ...;
let typed_func = func.typed::<(Vec<()>,), (), _>(&store)?; Is the first parameter It could be that the answer is simply "well that API isn't supported in the component model". |
Ah, right. So, if:
would things work out? |
I haven't really thought much about subtyping and such in the Rust bindings just yet. I was assuming that One possible idea is that in Rust when we say "is the Rust type |
Obviated by #69, which removed |
Currently interface types has both a
unit
as well as atuple
type, and the tuple type can have any number of fields. This raises a possible ambiguity for languages like Rust where the 0-tuple,()
, is equivalent to Rust's "unit" type, also()
. This might be a good opportunity to perhaps be a bit conservative and go ahead and make the 0-tuple a validation error perhaps?Additionally one other possible thing we may want to do is in addition to making 0-tuples a validation error we could also make 1-tuples a validation error as well. At least in Rust 1-tuples are convenient for macro-generated code and things like that but otherwise are pretty rarely used. 1-tuples are pretty hard to work with as they're syntactically
(T,)
(not to be confused with the(T)
type which is justT
). Given that the component model is probably pretty far from macro-generated things it might be good to go ahead and say that 0- and 1-tuples are validation errors? (with the possibility of opening them up in the future of course)The text was updated successfully, but these errors were encountered: