soma.cell

Nested config record with defaults, merge-style overrides, and a deep-path reader

Demonstrates a settings tree built from records and the ?? null-coalescing guard for optional fields.

A Soma program from the records part of the verified corpus: 58 lines, cells Config, ConfigTest. It passes soma check with soma 3.2.4.

How it is built

The cell Config declares 5 signals in its face: defaults() -> Map, server_port() -> Int, feature(name: String) -> Bool, override_port(p: Int) -> Map and describe() -> String. Handlers: defaults (line 14), server_port (line 22), feature (line 26), override_port (line 36) and describe (line 42).

The file also holds 1 test cell (ConfigTest) with 6 assertions, run by soma test.

Generated from soma describe on this file.

The source

config.cell

// Nested config record with defaults, merge-style overrides, and a
// deep-path reader. Demonstrates a settings tree built from records and
// the ?? null-coalescing guard for optional fields.

cell Config {
    face {
        signal defaults() -> Map
        signal server_port() -> Int
        signal feature(name: String) -> Bool
        signal override_port(p: Int) -> Map
        signal describe() -> String
    }

    on defaults() {
        return Settings {
            server: Server { host: "0.0.0.0", port: 8080 },
            db:     Db     { url: "sqlite://soma.db", pool: 4 },
            flags:  Flags  { dark_mode: true, beta: false }
        }
    }

    on server_port() {
        return defaults().server.port
    }

    on feature(name: String) {
        let f = defaults().flags
        return match name {
            "dark_mode" -> f.dark_mode
            "beta"      -> f.beta
            _           -> false
        }
    }

    // Copy-update the nested server record with a new port.
    on override_port(p: Int) {
        let c = defaults()
        c.server.port = p
        return c
    }

    on describe() {
        let s = defaults().server
        return "{s.host}:{s.port}"
    }
}

cell test ConfigTest {
    rules {
        assert server_port() == 8080
        assert feature("dark_mode") == true
        assert feature("beta") == false
        assert feature("ghost") == false
        assert override_port(9090).server.port == 9090
        assert describe() == "0.0.0.0:8080"
    }
}

What the toolchain says

Run on a fresh copy of the program at build time; the outputs are pasted unedited.

$ soma check config.cell
✓ All checks passed.
$ soma test config.cell
test ConfigTest ...
  ✓ assert server_port() == 8080
  ✓ assert feature("dark_mode") == true
  ✓ assert feature("beta") == false
  ✓ assert feature("ghost") == false
  ✓ assert override_port(9090).server.port == 9090
  ✓ assert describe() == "0.0.0.0:8080"

6 tests: 6 passed, 0 failed
$ soma verify config.cell
Verifying config.cell...
No state machine in this program: nothing to prove beyond `soma check` (invariants and lifecycles are what verify proves).
VERIFY OK (vacuous — no state machine)

Source file: /corpus/records/config.cell · examples/corpus/records/config.cell