FunctionaL-City

Primitives Ordinance Book

Subdivision: CivicAlgebraicInfrastructure.Foundations.Primitives
Companion files:

Preamble

This namespace collects domain-model primitives that serve as the foundational building blocks for CivicAlgebraicInfrastructure. The first primitive provided is the LiftedCell / Lifted type, a minimal, civic-grade union type that encodes payloads with explicit provenance and composable nesting. The module establishes clear, testable contracts for each primitive so remixers, migrators, and auditors can rely on structural, behavioral, and provenance guarantees.

Purpose

Primitives

This file defines the lightweight algebraic primitives used across the Civic Algebraic Infrastructure. It documents the LiftedCell shape, provenance model, and traversal / mapping semantics expected from implementations.

Provenance Contract

Provenance records authoritative lineage metadata for LiftedCell payloads and establishes the following guarantees.

Traversal and Fold Semantics

These traversal rules are ordinance-level guarantees so consumer code can depend on deterministic visitation order and accumulator behavior.

Map and Reassign Guarantees

Robustness, Performance, and Tests

API Signatures and Examples

Include the following canonical contract snippets in the ordinance so reviewers can treat the document as an executable contract for implementers.

type Provenance = {
  SourceName: string
  Step: int
  Timestamp: System.DateTime
  Note: string option
  Lineage: Provenance list
}

type LiftedCell<'a,'b> =
  | A of ARecord<'a>
  | B of BRecord<'b>
  | Nested of WrapperRecord<'a,'b>

val mapA : (ARecord<'a> -> ARecord<'a2>) -> LiftedCell<'a,'b> -> LiftedCell<'a2,'b>
val mapB : (BRecord<'b> -> BRecord<'b2>) -> LiftedCell<'a,'b> -> LiftedCell<'a,'b2>
val mapAll : (obj -> obj) -> LiftedCell<'a,'b> -> LiftedCell<'a,'b>
val collectProvenance : LiftedCell<'a,'b> -> Provenance seq
val tryFindProvenance : (Provenance -> bool) -> LiftedCell<'a,'b> -> Provenance option
val reassignProvenance : Provenance -> LiftedCell<'a,'b> -> LiftedCell<'a,'b>
val mkDerived : sourceName:string -> parents:Provenance list -> note:string option -> Provenance

Zoning Map

+----------------------------------------------------------------------------+
| Namespace: CivicAlgebraicInfrastructure.Foundations.Primitives             |
|                                                                            |
|  +----------------+    +----------------+    +---------------------------+ |
|  | Provenance     |    | LiftedCell<'T> |    | Lifted<'A,'B>             | |
|  | { SourceName;  |<-->| { Value: 'T;   |    | A of LiftedCell<'A>       | |
|  |   Step }       |    |   Provenance } |    | B of LiftedCell<'B>       | |
|  +----------------+    +----------------+    | Nested of                 | |
|                                              | LiftedCell<Lifted<'A,'B>> | |
|                                              +---------------------------+ |
|                                                                            |
| **Public API (module Lifted):**                                            |
|  mapA, mapB, mapAll, collectA, collectB,                                   |
|  collectProvenance, tryFindProvenance, fold, count, depth,                 |
|  reassignProvenance                                                        |
+----------------------------------------------------------------------------+

Provenance: Step formula and Timestamp rule

Implementers must compute Step exactly as:

Step = 1 + (parents |> Seq.map (fun p -> p.Step) |> Seq.tryMax |> Option.defaultValue 0)

Timestamps stored in Provenance must use UTC with an explicit DateTimeKind. Example construction:

let ts = System.DateTime.UtcNow.ToUniversalTime()
let p = mkDerived "source" parents (Some "note") // mkDerived must set Timestamp = ts and Step using the rule above

Flow Diagram

[Construct Provenance]    [Construct LiftedCell]      [Construct Lifted Tree]
       p1,p2,p3                 cellA,cellB                  A cellA
         |                          |                         |
         +-----------+--------------+-------------------------+
                     |                                       
            (nesting / composition)
                     |
              Nested { Provenance = pN; Value = <Lifted> }
                     |
             +-------v-------+
             |   Lifted Tree |
             +---------------+
                     |
     +---------------+-----------------+----------------------+
     |               |                 |                      |
 [printLifted]   [collectProvenance] [collectA/collectB]   [depth/count]
     |               |                 |                      |
  human view     [list of Provenance] [list of LiftedCell] [metrics ints]
                     |                 |                      |
                     +-----------------+----------------------+
                                       |
                                   [fold/mapAll]
                                       |
                             transformed Lifted tree
                                       |
                                [reassignProvenance]
                                       |
                             Lifted tree with new Provenance

Fold signature and example

Canonical signature to remove ambiguity:

val fold :
  ('acc -> ARecord<'a> -> 'acc) ->
  ('acc -> BRecord<'b> -> 'acc) ->
  'acc ->
  Lifted<'a,'b> ->
  'acc

One-line example showing accumulator ordering (counts A nodes by visiting root-first):

// counts A nodes in root-first, left-to-right order
let countA = fold (fun s _ -> s + 1) (fun s _ -> s) 0 nested

Glossary

The following termss define key civic primitives used throughout this ordinance.

Lifted

Definition: A civic union type representing payloads with optional provenance.
Variants:

Signage Overlay:
Lifted is the zoning envelope for payloads and provenance. It scaffolds remix-safe traversal, nesting, and audit overlays.

Provenance

Definition: A civic record capturing the lineage, timestamp, and derivation of a payload.
Fields:

Signage Overlay:
Provenance is the civic passport of a payload. It scaffolds audit trails, remix inspection, and timestamp guarantees. Immutable once assigned, it empowers remixers to trace civic lineage.

Step 1

Definition: The initial derivation index assigned to a payload with no prior lineage.

Signage Overlay:
Step 1 is the civic birthmark of a payload. It signals origin without inheritance, scaffolding timestamp semantics and remix-safe onboarding. All derived payloads increment from Step 1.

Lineage Trail

Definition: A recursive list of Provenance records representing the ancestry of a payload.

Signage Overlay:
The Lineage Trail is the civic ancestry map. It scaffolds remix inspection, ordinance tracing, and provenance guarantees.

Case Law (see .fsx)

This script is a runnable demonstration that exercises the Lifted primitives and their provenance semantics. It builds sample provenance records and payload cells, composes nested Lifted values, and exercises traversal, extraction, metrics, printing, and provenance reassignment.