Closed matthewhammer closed 3 years ago
This feels more like a service factory, rather than an actual service.
From MapThing<X,Y>
, you can create canister MapThing<Int, Int>
and canister MapThing<Text, Blob>
, and they each can dynamically create sharded canisters of the same type. But you cannot put
an arbitrary type X
into a particular canister. In this sense, the actor factory is polymorphic, but the actual actor stays monomorphic. Or you have something more general in mind?
I think this stance makes sense, but I'm not certain that I agree (yet). Just to clarify, are you saying that type arguments are never an issue for Candid, and only ever for a language using Candid, like Motoko?
I think it's still nice for Candid to support type arguments, but I'm not sure how useful it is for a container canister. Even for a local function, I don't know what to do with a generic HashMap<K, V>
. Because you don't know the concrete type of K, you cannot put any real value into HashMap<K, V>
.
Is your feature request related to a problem? Please describe.
I want to write an actor/service like this in Motoko, with a corresponding Candid service type:
Leaving out some inessential details, this
MapThing
actor provides a service whose API is parametric in two types,X
andY
, for a generic key and value type, respectively. It stores a dynamic map fromX
s toY
s.More generally, I want to author Candid services that use generic type arguments, and as a user, instantiate services by providing these types over the network.
Describe the solution you'd like
The solution here involves extending Candid, Motoko, as well as (perhaps) the Internet Computer itself.
Describe alternatives you've considered
Many systems and languages lack polymorphic types. The usual workarounds map a polymorphic design into a monomorphic one, somehow. For instance, we could assume a single choice of type for
X
andY
above, and try to provide a way to map into and out of these single choices (e.g., use[nat8]
for all types and do extra layers of serialization, the current solution).Additional context
None.