Are there any recommended strategies how one might represent generics in a wit signature or in core WASM? I’d like to describe a module from a standard lib for a small programming language in wit but I know it doesn’t support custom generic types, does anyone have any hints on how I can represent and process such a thing in wit? What kind of protocol I’d need to come up with?
combine: a -> a -> a
Identity: a -> a
For example the above 2 functions
One approach might be to make a
be a handle to a resource, and then implement dynamic typing within that resource.
But another approach is to consider that a standard lib for a language with a sophisticated type system may not be an advantageous place to use Wit, at least as long as Wit lacks custom generics.
Thanks for the suggestion
I am using a combination of resource
types and variant
types to model something genericish. The container resource holds the data, it is instantiated with an enum
describing the generic child type, and it returns the child data wrapped in a variant
the describes the type and holds the data. Not the prettiest thing in the world, but it works for the moment.
resource container{
constructor(input: container-input);
get-data: func() -> container-data;
get-child: func() -> container-child;
}
variant container-child {
foo(foo-data),
unmodeled(string),
}
record container-input {
child-event-type: container-child-types,
data: string
}
enum container-child-types {
foo,
unmodeled,
}
Last updated: Dec 23 2024 at 12:05 UTC