Wikifunctions:Type proposals/configuration of functions for given types
Summary
This will perform a similar role to Z14294, but instead of splitting the functions by Z60, it will split them by Z4 (likely to switch the function according to its input, output, or both).
Uses
Prompts:
- Why should this exist?
Some linguistic functions branch naturally according to the dialect. Similarly many functions branch according to the type of input they are given (and/or the output desired).
- What kinds of functions would be created using this?
- We will be able to perform Z13052, but direct the comparisons toward the correct type-specific equality functions.
- We will be able to appropriately group type-specific versions of the same function with an overarching meta function. For example, we are likely to have a version of Z13663 for most other numerical types we enable (integers, reals, complex numbers...).
- A function written for Z16098 could easily be generalised to apply to other types of months in other calendar systems.
- What standard concepts, if any, does this align with?
It is very similar to Z14294, and like it, will need a related type like Z14293.
Structure
Similar to Z14294. Values would have a list of options. Each option has a function to use for that option and a list of types describing the option to choose. There is also a default function on the main object.
Example values
Example value for multiplication configuration
{
"type": "configuration of functions for given types",
"options": [
"function option of a type",
{
"type": "function option of a type",
"function to use": "multiply two natural numbers",
"for these types": ["Type", "Natural Number", "Natural Number"]
},
{
"type": "function option of a type",
"function to use": "multiply signs",
"for these types": ["Type", "Sign", "Sign"]
},
{
"type": "function option of a type",
"function to use": "multiply integers",
"for these types": ["Type", "Integer", "Integer"]
}
],
"default function": "raise type error"
}
|
{
"Z1K1": "Zmmmmm",
"ZmmmmmK1": [
"Znnnnn",
{
"Z1K1": "Znnnnn",
"ZnnnnnK1": "Z13539",
"ZnnnnnK2": ["Z4", "Z13518", "Z13518"]
},
{
"Z1K1": "Znnnnn",
"ZnnnnnK1": "Z16728",
"ZnnnnnK2": ["Z4", "Z16659", "Z16659"]
},
{
"Z1K1": "Znnnnn",
"ZnnnnnK1": "Z17120",
"ZnnnnnK2": ["Z4", "Z16683", "Z16683"]
}
],
"ZmmmmmK2": "Zooooo"
}
|
Validator
The validator ensures that:
- There are no entries with same list of types as another entry
Identity
Two configuration of functions for given types are the same if they map to the same function for every language (order in the list should not matter).
Converting to code
Python
A dict will be returned to Python code.
JavaScript
An object will be returned to Javascript code.
Renderer
We will use the regular UI for renderering and it will not have a string renderer
Parsers
We will use the regular UI for parsing and it will not have a string parser
Alternatives
Feel free to suggest.
Comments
Support as proposer. --99of9 (talk) 08:43, 27 March 2024 (UTC)- Strangely, we didn’t get a Type proposal for Z14294. My intuition is that this current proposal is logically prior to that one, and I think they both need to be considered along with Wikifunctions:Representing identity. I’m guessing there will be no progress there until after Easter. I’ll add this proposal to that page’s discussion later (if no one else does). I don’t yet see any reason to oppose this particular proposal, however.--GrounderUK (talk) 11:02, 27 March 2024 (UTC)
- Please see Wikifunctions talk:Representing identity#Type safety
- The most significant difference between this proposal and Z14294 is that this is more clearly “type distributive” or “type convergent”, and these cases could usefully be distinguished. Where functions are grouped by similar arguments but produce different types of result (their return types are not common but their arguments are: “type distributive”), we should ensure that each of the possible resultant types is valid in the immediate context. This is easier when the functions produce the same type of result from diverse forms of input (“type convergent”) but it suggests that the appropriate function may depend on factors other than type (or language), such as the number of inputs or the range within which some input falls.
- Essentially, that would make this proposal and the language-driven version, a case construct. If that is the intention, at least in part, we should seek to ensure that lazy evaluation applies and, if feasible, that only the required branch is orchestrated prior to evaluation (which should itself deliver lazy evaluation). GrounderUK (talk) 15:34, 5 April 2024 (UTC)
- Yes, that clarification of intention seems helpful. --99of9 (talk) 01:36, 26 September 2025 (UTC)
Support I think this would be way cleaner than have dozens of different functions that still do the same thing conceptionally but edit different types. This will become more and more beneficially as new types start to be introduced. -ListWorshiper (talk) 16:09, 04 April 2024 (UTC)
Strong support The current system is already quite annoying for the integer (add Integers (Z16693)) / natural (add two Natural numbers (Z13521)) / string (add two integer strings (Z10782)) split, and I can't imagine this getting any better with the other numeric types (float64, complex128 and fraction). infernostars (talk) (contribs) 18:00, 30 August 2024 (UTC)
Support Dv103 (talk) 10:40, 26 April 2025 (UTC)
Support SRG372 (talk) 16:58, 6 July 2025 (UTC)
Support Feeglgeef (talk) 16:05, 26 January 2026 (UTC)
Question for implementation
I was planning to implement this Type, given its strong support, but wanted to clarify how exactly it should look like. Just a question:
- I first thought it is the same structure as Z14294 and Z14293, just with Z60 replaced by Z4. But the example given above seem to indicate that the K2 of the option type indicates not a list of possible types for which to use the given function, but rather the signature of the types? Does this include just the arguments? Or both the arguments and the return type? Or do we want to leave that open and be agnostic with regards to that question? This is more informative, as this could be left agnostic.
- But this question isn't: If the options are indeed the signatures, and not just a list of types, should we then rather have a list of list of types, instead a list of types, for the K2 of the function option?
Pinging @99of9, GrounderUK, ListWorshiper, Infernostars, Dv103, and SRG372: --DVrandecic (WMF) (talk) 08:19, 15 October 2025 (UTC)
- I didn't think that deeply when proposing, sorry. It looks like @ScienceD90 made the example for us. I'm sure @GrounderUK will have a good opinion on this. My initial impulse is that allowing us to specify a list of types is a helpful generalisation. I expect they will often correspond with the types in the function signature, but maybe not always. So I think I'd be comfortable with a flat list of types. But on the other hand your list-of-lists suggestion is more general, so may allow ultimate flexibility down the track. --99of9 (talk) 02:29, 16 October 2025 (UTC)
- I wouldn’t be so sure, but I’m thinking about it!
- Also considering:
- a built-in untyped switch function (with lazy evaluation)
- a Type proposal for Function signature (not for use within Function (Z8) but for functions that expect or return a signature)
- Wikifunctions:Type proposals/Wikifunctions object reference
- Then there’s a general reservation about the untidiness of the Type (Z4)/Reference (Z9) union via Object (Z1) – phab:T389183 etc., with added complexity for the identity of a Function call (Z7) to Typed enum of Wikidata references (Z6884) and properly generic types. GrounderUK (talk) 12:15, 16 October 2025 (UTC)