API to specify a function name and multiple signatures in a single file #12
Loading…
Add table
Reference in a new issue
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've been reading https://code.studioinfinity.org/StudioInfinity/nanomath/wiki/Item-Specifications, and now I'm thinking about how to specify multiple signatures of a single function in a single file in a neat way.
Maybe it is interesting to do something like this, putting the function name as a factory function argument:
And then, to implement multiple signatures:
Or maybe rename
onType
intocreate
orfactory
, for example:Thinking about it, it could also just be wrapping signatures in an array:
What do you think?
Well currently I just allow
(see
src/core/__test__/TestDispatcher.spec.js
at line 20, for example). In other words, you can just alternate type patterns and corresponding values, for as many or few as you like (often just one pair). This convention seemed to me to be the simplest analogue of the object key - value interface in mathjs 14. But do you like it better how it looks if you repeatonType
for each type pattern?Or if you like a list of pairs better, we could switch to
or something like that.
Another alternative, if you don't mind repeating a function symbol, would be:
Here we avoid parsing by having our
pattern
function set up to return a string which more or less acts like a hash -- it puts the actual TypePattern object into some global repository, keyed by that string. Then when thisadd
definition gets merged into the TypeDispatcher, it looks up the keys of the object associated withadd
in that global repository to find the TypePatterns it should use. Don't get me wrong, the string returned bypattern
could be human-readable; it just has to be different for each different TypePattern.But the notation I currently implemented is the most concise one I could think of.
Let me know which of these conventions you prefer and if it's different than the current one, I will make a PR to switch this prototype over. Same goes if you come up with some "sleeker" for return-type annotations.