Parametric polymorphism and async

Is it possible to write a function whose type is <A> (A) -> async A?

At the moment I get errors like type error, async has non-shared content type A/52

This makes me think there’s a way to say that A must be constrained to the set of values that are shared but I haven’t been able to figure out how to do that.

We don’t support polymorphism for async functions. It has to be a concrete sharable type. There is no notion of type class, so we cannot constrain the type variable.

1 Like

Thanks Yan.

I think you’re saying this is a limitation of Motoko and not the IDL (probably because things will need to be specialized by then anyway)

Is that right?

I would say it’s the limitation of both. We need to extend both type systems to support this. It’s theoretically possible to transmit polymorphic values over the wire, but not a very high priority.