a value declaration should be able to name a scalar type

Aperta
#73 0 commenti 2 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
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
compilers

Direzione di ricerca

Nell’issue non sono indicati file o test. Inizia individuando i percorsi del parser e del type-checker per le dichiarazioni di valori, poi risolvi Q1–Q3 prima di scegliere la sintassi. Il lavoro è completo quando una dichiarazione scalare può essere analizzata, può essere referenziata come LogOffset e le semantiche di assegnazione, confronto e aritmetica sono coperte dai test.

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

Descrizione

language suggestion

tl;dr

  • A value declaration must have a braced body, so a scalar can't be given a domain name
    value LogOffset: Integer fails to parse. The only way to say "this Integer is a log offset" is a plain Integer field with a descriptive field name — which puts the name on the field rather than on the type, so nothing carries it to the next use site.

  • The one-field wrapper workaround asserts structure that isn't there
    value LogOffset { offset: Integer } checks clean, but every use site reads through .offset, and the spec now claims LogOffset is a composite when it's a number.

  • The language reference already offers this and it doesn't exist
    The primitive types section tells the reader to use "value types or plain String fields with descriptive names" for domain-specific string types. A value type needs at least one field, so that's a one-way choice dressed up as two.

  • What LogOffset is needs settling before the syntax does
    Transparent alias or a distinct type (Q1) decides what the checker does with offset = 0 and with a.offset - b.offset.

Context

The everyday case for naming a type descriptively is a scalar, not a record: LogOffset, EmailAddress, Path, Millis, TenantId. Each is an Integer or a String that means something specific, and the meaning is exactly what a spec reader needs to see at the point of use.

Allium's value keyword is the natural home for that, but it's shaped for structured data only — the language reference introduces value types as "structured data without identity", with TimeRange and Location as the examples. There's no declaration form for the unstructured case.

Came up writing a spec with several distinct Integer-typed quantities in play, where offset: Integer and count: Integer sitting next to each other tell the reader nothing about which values are comparable with which — and there's no declaration form that can.

Current state

value requires a {:

-- allium: 3

value LogOffset: Integer

entity Log {
    offset: LogOffset
}
error  t.allium:3:16  expected '{', found ':'
error  t.allium:6:13  allium.type.undefinedReference
               Type reference 'LogOffset' is not declared locally or imported.

(allium 3.5.3)

The wrapper workaround passes, at the cost of a field the domain doesn't have:

value LogOffset {
    offset: Integer
}

entity Log {
    latest: LogOffset
    is_empty: latest.offset = 0     -- .offset is pure ceremony
}

Open questions

  • Q1 — is a scalar value a transparent alias for its underlying type, or a distinct type?
    Nominal is what makes the feature worth having: if LogOffset and MessageCount are both just Integer, the checker can't tell you you've compared one to the other, which was the point. But nominal has to answer what happens to arithmetic and comparison — whether LogOffset - LogOffset yields a LogOffset, an Integer, or an error, and whether the literal 0 is assignable to a LogOffset field.

  • Q2 — which type expressions are allowed on the right?
    Just the primitives (value Millis: Integer), or the full field type grammar including compounds and optionals (value Offsets: List<Integer>, value MaybeName: String?).

  • Q3 — can a scalar value carry derived values or invariants?
    A braced value type hangs them off its fields; a scalar has no field to name. If value Percentage: Decimal wants to constrain itself to 0..100, there's no established place to write it.

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.