Skip to content

[Human Guide] Add 'Status sum vs string enum' idiomatic pattern #52

Closed

Description

@hyperpolymath

Proposal

Add an idiomatic pattern to the Human Guide for status sum types over stringly-typed enums. Small but pervasive in real .res/.ts/.js code. Migration target should be obvious.

Source observation

idaptik's Main.res has MultiplayerScreenWiring.dispatchDeviceStatusChanged(deviceId, "compromised"). Stringly typed. Typo "compromied" would compile and silently mis-match. The AffineScript translation introduces a sum type:

type DeviceStatus = Compromised | Clean | Suspect | Unknown;

Now typos are compile errors and match is exhaustive. Trivial change with high return.

Where to put it

Add to the Idiomatic Patterns chapter, as a peer to Branded Identifiers.


Filed from idaptik Wave 3 pilot. See LESSONS.md and PILOT.md. Idaptik commit hyperpolymath/idaptik@aef38db.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions