Sum types for value declarations?

Aperta
#77 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Ambito
tooling

Direzione di ricerca

This is an open language-design question, not a ready task: first get a maintainer decision on whether variant should apply to value declarations. Read the language reference's sum-type section and the existing variant X : BaseEntity rules. The issue reports that allium check accepts variant on a value and does not validate when effect = nonsense, so those checks are the concrete behaviour to examine. Done means an agreed rule, reference text, and checker tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hey,

I'm writing a spec for a small macOS app and ran into a case where a value would really want to be a sum type. An action is either a key combination, which needs its keys, or a mouse click, which has none:

enum Effect { key_combo | left_click | right_click }

value KeyCombo {
    modifiers: Set<KeyModifier>
    key: String
}

value Action {
    effect: Effect
    keys: KeyCombo?        -- only for effect = key_combo
}

Right now the "keys only for key_combo" part lives in a comment and a derived is_complete, so the spec can still describe a click that carries keys, or a key combination without them.

Sum types came in with #3 / #4, but only for entities (variant X : BaseEntity). The issue itself talks about "a value is exactly one of A or B", so I wasn't sure whether leaving out values was intended or just didn't come up.

What I noticed with allium check 3.6.1:

  • variant KeyAction : Action on a value is accepted, and an undeclared variant name in the discriminator is reported. So it kind of works already, but the language reference doesn't cover it.
  • keys: KeyCombo when effect = key_combo inside a value is accepted too, but when effect = nonsense passes as well, so I don't think that's checked.

Are sum types on values something you'd want to support? Or is there a different way you'd model this?

Lingua principale
JavaScript
Stelle
538
Fork
29
Merge medio
4g 3h
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di juxt/allium

Tutte le issue di juxt/allium

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.