RaggieSoft Labs • Linear-Type Financial Compiler Research (v0.1.0-lab)

Fin# (Financial Sharp) — Enforcing Conservation of Capital at Compile Time.

“Because rules made by monopolies can be questioned. The laws of conservation cannot.”
Originating in RaggieSoft's Ocean View Archives novel series (/books/aubrie, Chapter Question The Rules: The Birth of Fin#) and now under active engineering design in RaggieSoft Labs, Fin# (FinSharp / finsc) brings linear resource types to the .NET & Roslyn compiler ecosystem—turning unbalanced double-entry accounting entries, binary floating-point rounding drift, and synthetic revenue creation from post-facto audit findings into hard compile-time errors.

The Core Bug in Imperative Finance Code

Standard Imperative Languages (C#, Java, C++, COBOL)

Money Treated as an Unconstrained Scalar

In general-purpose languages, decimal is just a mutable number. A developer or rogue script can write companyRevenue += 500_000_000.00m; and the compiler succeeds with 0 errors and 0 warnings—even though half a billion dollars appeared out of nowhere with zero corresponding debit, and fractional allocation remainders can be silently dropped into garbage collection. Sarbanes-Oxley (SOX Sections 302 & 404) only catches the corruption months later during human audits.

Fin# Linear Resource Type System (finsc)

First Law of Thermodynamics Applied to Luca Pacioli (1494)

Just as quantum programming languages forbid cloning or deleting an entangled qubit, Fin# models Capital<TCurrency> as a protected linear resource type. Capital cannot be instantiated out of thin air, overwritten, or dropped at scope exit; it can only move inside a balanced transaction block where the compiler symbolically proves Σ Debits == Σ Credits before emitting a single instruction of .NET IL!

Interactive Compiler Diagnostic Simulator • finsc v0.1.0-lab

Test How finsc Rejects Unbalanced Capital & Verifies Double-Entry Ledgers

// File: QuarterlyClose.fin — Attempting unconstrained scalar addition on an Account
ledger CorporateBooks<USD> {
  account OperatingCash    : Asset<USD>;
  account WholesaleRevenue : Revenue<USD>;
}

fn BookSyntheticGain(books: ref CorporateBooks<USD>) {
  // Illegal in Fin#: where did 500,000,000.00 USD come from? Which account was debited?
  books.WholesaleRevenue += 500_000_000.00_USD;
}
Build FAILED (Exit Code 1) — Halted Before IL Emission:
QuarterlyClose.fin(9,3): error FIN0001: ConservationOfCapitalViolationException —
  Account 'WholesaleRevenue' (Revenue<USD>) cannot be mutated via scalar '+=' outside an atomic
  'transaction' block with a proving Debit counterparty of equal Capital<USD> magnitude.
// File: DividendSplit.fin — Splitting $100.00 USD equally across 3 accounts ($33.33 * 3 = $99.99)
transaction AllocateGrant(pool: move Capital<USD>) {
  // Exact 3-way floor division returns a linear tuple: (quotient[3], remainder: 0.01_USD)
  let (shares, unallocatedCents) = capital.splitEqual(move pool, parts: 3);

  debit  DeptResearch <- move shares[0];
  debit  DeptTransit  <- move shares[1];
  debit  DeptAquatic  <- move shares[2];
  // Oops! 'unallocatedCents' (0.01_USD) goes out of scope without being posted!
}
Build FAILED (Exit Code 1) — Linear Resource Leak Detected:
DividendSplit.fin(10,1): error FIN0005: UnconsumedLinearCapitalError —
  Linear binding 'unallocatedCents' of type 'Capital<USD>' goes out of scope unconsumed!
  Route the exact remainder explicitly (e.g., 'debit RoundingReserve <- move unallocatedCents;').
// File: AquaticMembership.fin — Verified balanced journal entry + Z-SOX-302 audit hash
ledger HouseholdLedger<USD> {
  account CheckingAccount          : Asset<USD>;
  account RecreationAndPhysicalTherapy : Expense<USD>;
}

fn RecordMonthlyKeytag(books: ref HouseholdLedger<USD>) {
  transaction "Christiansburg Aquatic Center Non-Resident Keytag" [audit: Z_SOX_302] {
    debit  books.RecreationAndPhysicalTherapy : 30.00_USD;
    credit books.CheckingAccount              : 30.00_USD;
  }
}
Build SUCCEEDED (0 Errors, 0 Warnings — Conservation Proof Verified in 1.4 ms):
[OK] finsc AquaticMembership.fin --target=net11.0 --verify-linear-conservation
     Proved: Sum(Debits<USD>) [30.00] == Sum(Credits<USD>) [30.00] (Delta == 0.00_USD)
     Emitted: AquaticMembership.dll + Z-SOX-302 deterministic ledger proof manifest.

Core Compile-Time Type Rules & Diagnostic Codes

Fin# v0.1.0-lab Compiler Invariants & Fatal Diagnostic Gates
Code Compiler Invariant What It Prevents at Compile Time
FIN0001 Conservation of Capital (ConservationOfCapitalViolationException) Blocks thin-air currency literal creation, overwrite, or scalar += / -= on accounts outside a balanced transaction.
FIN0002 Balanced Double-Entry Proof (Σ Debits == Σ Credits) Rejects any transaction block whose concrete or symbolic debits and credits do not balance identically per currency.
FIN0003 Zero Binary Floating-Point (IEEE 754 float / double Banned) Eliminates 0.1 + 0.2 != 0.3 base-2 drift by enforcing 128-bit scaled fixed-point arithmetic on all monetary types.
FIN0004 Dimension-Typed ISO 4217 Currencies (Capital<USD> vs. Capital<EUR>) Prevents accidental cross-currency addition without an explicit, timestamped FX conversion & settlement bridge.
FIN0005 Linear Remainder Conservation (No Silent Rounding Drops) Forces division/proration operations to return (shares, remainder) linear tuples where every single cent must be routed.

Compiler Engineering Roadmap & Potential RaggieSoft Studio Integration

Clean C# “Mini-Roslyn” Frontend → .NET 11 / Roslyn Backend

Rather than carrying a 4-million-line upstream dotnet/roslyn merge burden, our primary architecture pairs a crisp, 100-level-commented C# immutable syntax/binding/linear-flow frontend (FinSharp.Compiler) with in-process Microsoft.CodeAnalysis.CSharp lowering & PE emission—delivering sub-second builds, full NuGet interoperability, NativeAOT support, and PDB debugging!

Candidate Studio Tool: RaggieSoft Fin# / Ledger Studio

Pairing Accessibility Studio's proven .NET 11 + Monaco workstation shell with a live Fin# Language Server (LSP), real-time T-account conservation diagrams, Z-SOX-302 audit proofs, and Document Studio Tagged PDF/UA-1 statement generation—following our permanent Community == 100% Architect rule.