if i have a parameter
handler : <system>(Route.RouteContext) -> Route.RouteResult,
so i am able to have users specify a method that is not async*, but are able to use functionality. The weirdness I have found is that the function MUST have ,even if its not needed vs it being allowed to be used
Is this intended?
I am trying to create a routing library and users will have to specify every time or I have to have 2 different ways of registering system vs non-system which makes it more complicated
No a giant issue but weird/annoying
That’s unfortunately a limitation of Motoko’s treatment of generic functions.
A more general generic function can’t be promoted by subtyping to a less general generic function. You need to use an explicit correction (i.e. defining a more specific wrapper function that dispatches to the more general one).
The upside is that Motoko let’s you use generic functions as first class values and has subtyping.
Other languages make different trade-offs. For example ML family languages let you implicitly use polymorphic functions at less general types, but don’t support subtyping or polymorphic functions as first class values.
1 Like