Wikifunctions:Type proposals/Either
Summary
For the top-level overview of union types on Wikifunctions, see phab:T292892.
Yoshi's stop-gap Either summary
An (undiscriminated) union type (Q893290) of two Types à la TypeScript and various FP languages.
Can be extended to 3 or more Types by nesting: Either(A, Either(B, C)).
The constraint of values being of either the left or right Type is not enforced by the dynamic typing system,
making it equivalent to the top type (Q4129836) (Object (Z1)) as far as machines are concerned. The Type annotation containing Either is intended for humans.
Uses
See discussion on phab:T292892.
Currently, many Functions are declared with a certain Type in their signatures—usually Object (Z1)—where a union would be more appropriate.
- Day of Roman year (Z20342) and Functions for it use void for some fields, meaning those are effectively unions with Unit (Z21).
- Wikidata datetime (Z6061) is set up for a discriminated union of Gregorian calendar date (Z20420) and a yet-to-be-made Julian date.
- Fetch Wikidata entities (Z6820) uses Z1 instead of a union of Z6091/Z6092/Z6094/Z6095/Z6096.
- join text-like objects into HTML fragment (Z32234) uses Z1 instead of a union of Z89/Z11/Z6.
- get result or Error of quoted Function call (Z30824) should use a union of Z5 and the return Type of the given Function, but since that's expressed as Z1 the union is equivalent to Z1.
Structure
Discuss possible structures for a discriminated union on phab:T296326.
Yoshi's stop-gap Either structure
In this scenario, Either is a 2-ary Function which discards the arguments and returns a Reference to Z1. (Might have to override Z4K1?)
While it resembles Typed pair (Z882), there is no parameterised Either Type.
Since it would be a Function and not a Type, it should be possible to implement without code changes or other staff intervention.
Identity
Yoshi's stop-gap Either: N/A as it returns a Reference to Z1.
Converting to code
Yoshi's stop-gap Either: N/A as it returns a Reference to Z1.
Display function
Yoshi's stop-gap Either: N/A as it returns a Reference to Z1.
Read function
Yoshi's stop-gap Either: N/A as it returns a Reference to Z1.
Alternatives
A 'discriminated' a.k.a. 'tagged' union; see phab:T296326.
Comments
See discussion on phab:T296326.
See also WF:Type proposals/configuration of functions for given types.
Yoshi's stop-gap Either comments
For general comments, please reply to the proposer.
Support as proposer. I'm not sure if the Type annotations in the frontend work how I imagine they do (can you set Z4K1 to a Function call to Either without creating a clone of Z1?), but if they do then this would be a free UX win, working with the existing processes and constraints of the site. YoshiRulz (talk) 10:46, 7 July 2026 (UTC)