WebAssembly / component-model

Repository for design and specification of the Component Model
Other
933 stars 79 forks source link

Multi-return named type with result #196

Closed omersadika closed 11 months ago

omersadika commented 1 year ago

Today I can have multi-return named type in functions in WIT:

interface named {
  f: func() -> (u1: u32, u2: u32)
}

Many times, I will use it together with result, but when I do it, I can't return named type anymore, only tuples, so I want to do something like that:

interface named-result {
  f: func() -> result<(u1: u32, u2: u32), string>
}

It is very similar to tuples with the named tuple, but can be used outside of function. Is there any way to achieve that? Maybe a way to name tuple types?

pchickey commented 1 year ago

A named tuple type is a record. The syntax for a tuple, in wit, is e.g. tuple<u32, s32, string>

Functions can return multiple types by naming them. Despite using a syntax like tuples use in some languages, this is distinct in the type system from a tuple or a record: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#wit-functions

omersadika commented 1 year ago

Thanks @pchickey!

The significant difference is that you don't have to define tuples unlike records, and in some cases creating many records makes it complex. If there is no way to achieve that probably tuples without names will be the simplest solution.