Jump to content

Wikifunctions:Type proposals/Either

From Wikifunctions
Tracked in Phabricator:
Task T292892

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 signaturesusually Object (Z1)where a union would be more appropriate.

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 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)reply