Implement basic dispatch. #10

Open
opened 2024-10-21 22:03:27 +00:00 by glen · 2 comments
Owner

I believe all is ready to write a simple dispatcher.

I believe all is ready to write a simple dispatcher.
Collaborator

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.

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.
Author
Owner

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?

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?
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: glen/math5#10
No description provided.