Implement basic dispatch. #10
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I believe all is ready to write a simple dispatcher.
Yes! Are you going to give this a shot? As soon as there is a bare-bone implementation, I think I can start working on implementing more functions for it.
Indeed, I have already begun playing around with the code. Since this is a prototype/proof of concept, I was going to take an initial stab at a slightly different architecture for the dispatcher:
In typed-function, signatures are sorted, and then selected by type-testing the actual arguments one-by-one against each signature. The operation "typeOf" is then implemented by assembling a number of constant functions with different signatures.
In the initial prototype I am trying, the operation "typeOf" will be more fundamental, and implemented by special-purpose code that goes through the sorted list of registered types. Then to dispatch a call, typeOf is applied to the actual arguments to produce a string encoding the actual argument call signature, e.g.
number,Complex<number>,string
. This string is then used as a key with which to look up the proper implementation. If the lookup fails, there will be a backup implementation that for example checks if any new template instantiations need to be created to handle this argument list (updating the lookup table for the operation, if so, before dispatching to that implementation).A couple of questions:
(A) Do you know of any reason why actual-call-signature based hash map lookup to get the implementation, rather than sequential run-the-type-tests selection, is a bad idea?
(B) If not, do you have any intuition as to whether it's better to use a JavaScript Map or a plain object for the hash map from signature keys to implementations?