Programming Harness
SimpleModeling uses programming mechanisms centered on Scala as a harness for AI-assisted development. Building on direct model execution and code generation, Episode 6 explains how types, composition rules, shared APIs, and checks support integration code and business-specific processing supplied by AI.
The role of a programming harness
A programming harness defines the implementation structures and operations available to AI and limits errors and departures from them. Its purpose is to prevent mixed-up values, hidden dependencies on shared state, and missing failure handling without relying solely on individual care.
Appropriate reuse of existing functionality reduces the scope of AI’s independent design and implementation. Code that must be added receives both a less error-prone structure and conditions for checking conformance. Together, these two functions reduce the burden of AI decision-making and correction.
The programming harness in SimpleModeling
The reference architecture introduced in Episode 5 divides responsibilities among models, generated code, shared runtime infrastructure, and AI-written supplementary code. Here, model-defined specifications are carried into that supplementary code through typed APIs.
Connect model-derived types to reuse and glue code
Textus directly executes executable parts of CML models, while Cozy generates typed APIs and implementation integration structures. Explicit input, output, and connection conditions help AI identify available functionality and how to use it.
AI supplies glue code connecting components and business-specific processing absent from existing functionality. Type information guides conversions and integration, and the compiler detects incompatible connections. Precise typed specifications support both reuse and supplementary code construction.
Use shared infrastructure operations from supplementary code
Shared infrastructure supplies mechanisms for persistence, external communication, asynchronous execution, and failure handling; supplementary code uses them through public APIs. With business processing descriptions separated from execution management, types, pure functions and composition rules, and component checks constrain the supplementary code. The following sections explain the constraints each mechanism provides.
Detect confused values and missing cases with types
Types can distinguish values with the same representation by their business meaning and define the possible kinds of processing outcomes. Mixed-up values and missing cases illustrate the conditions that can be applied to AI-generated code.
Preserve the meaning of identifiers and quantities
If customer and order identifiers are both strings, swapping them still passes type checking. Distinguishing CustomerId and OrderId with facilities such as Scala's opaque types lets the compiler detect arguments of the wrong type.
Conditions such as a quantity’s permitted range are checked when a value is constructed, and only successfully checked values are passed in the dedicated type. Preserving that construction path and requiring the type in subsequent functions carries the checked conditions forward. AI-written code uses the same types, helping detect misuse and reduce duplicate checks.
Handle all defined states and result variants
Defining result variants with an algebraic data type (ADT) and handling them through pattern matching exposes missing cases when a result is added. For example, adding a reservations-suspended result to inventory reservation can reveal unhandled call sites when exhaustiveness warnings are treated as build errors.
Catch-all cases can hide additions and therefore require review. Exhaustiveness checking can report missing cases even when AI generates only the success path. Types can also represent states, while state-machine rules determine which transitions are permitted.
Connect proofs through types to practical checking
The Curry–Howard correspondence views types as propositions and programs of those types as proofs. In its basic form, proofs in intuitionistic propositional logic correspond to programs in the simply typed lambda calculus. A function type A → B corresponds to the proposition that A implies B.
In these examples, business distinctions and connection conditions are expressed in types, allowing the compiler to reject code that does not satisfy them. Broader type-level guarantees reduce the conditions requiring repeated individual verification or AI review. Ordinary Scala type checking does not prove termination or overall business behavior, but mechanically applying the same conditions after generation and correction has practical value.
Reference: Philip Wadler, Propositions as Types, Communications of the ACM 58(12), 2015. https://homepages.inf.ed.ac.uk/wadler/papers/propositions-as-types/propositions-as-types.pdf
Constrain implementation structure through pure functions and composition rules
Even when types check values and connections, code must still express sequencing, state dependencies, and failure handling. Representing calculations as pure functions and composing processing through shared rules also constrains this part of the implementation structure.
Why adopt advanced composition rules
Cloud-native applications need to remain responsive under changing loads and partial failures. The Reactive Manifesto identifies four characteristics for this purpose: responsiveness, resilience, elasticity, and message-driven communication (https://www.reactivemanifesto.org/).
Implementing asynchronous processing and failure handling separately in business code requires individual management of sequencing and failure control. Composing the typed operations exposed by shared infrastructure with monads and applicatives, according to dependency or independence, reduces the complex execution control written individually. Runtime infrastructure supports reactive characteristics; composition rules let business code use those mechanisms.
Pure functional programming, monads, and applicatives can be demanding to learn and write, but AI’s ability to write the code makes them easier to adopt. Supporting its output with types, shared APIs, and checks makes the benefits of these advanced techniques available in practice. Reducing custom control implementations and repeated correction and review aims to lower the development time and AI usage cost required to achieve the necessary quality.
Keep hidden-state dependencies out of calculations
Reading the current time or a changing price list inside a function can produce different results for the same arguments. Passing the required time, price list, and rule version as arguments and keeping data immutable makes the calculation a pure function with the same result for the same inputs. Business-rule evaluation similarly separates acquiring facts from applying rules to fixed facts.
Requiring explicit inputs and immutable data guides AI away from calculations that depend on or mutate shared state. Scala's val and function types alone do not guarantee purity, so checks and review examine the APIs and dependencies used. Combining the prescribed structure with conformance checks limits errors caused by hidden state and localizes corrections to functions and inputs.
Standardize outcome and error-handling rules with Consequence
Textus/CNCF represents function outcomes with Consequence. Successful outcomes carry a typed value; failures carry a Conclusion with structured error classification, cause, and handling guidance. Applying a shared system to result composition and error interpretation constrains AI from inventing different failure representations for each function.
Processing that depends on an earlier result uses Consequence’s monadic composition. flatMap passes a successful value to the next operation and propagates a failure without continuing that operation. Types check the connections, while shared composition rules propagate failures, reducing the need for AI to reimplement branches.
Independent input checks use applicative composition through Consequence’s zip-based APIs to aggregate errors across fields. The API choice expresses whether dependent processing stops on failure or independent checks collect errors. Design and review establish whether that choice matches the required business failure handling. Applicative composition expresses independence; it does not itself guarantee concurrent execution.
Separate operation descriptions and execution with UoW and a Free Monad
Standardizing outcomes and failures with Consequence still leaves a separate decision about where persistence and external calls execute and which mechanism manages that execution. In Textus/CNCF, UoW (Unit of Work) provides the execution unit and shared execution management for a series of operations. Describing and composing operations with a Free Monad and passing their execution to UoW’s shared mechanisms separates the composition of business processing from execution management.
Describe UoW operations through a typed internal DSL
Persistence and external-call operations executed within a UoW each have defined input and result types. An internal DSL provides APIs for describing and composing these typed operations in Scala. AI uses the public operations to describe component integration and business-specific processing.
Expressing operation kinds and connection conditions in APIs makes the implementation mechanisms available to AI explicit. Type checking detects incompatible connections. Departures that types alone cannot identify, such as direct calls bypassing the shared execution path, are examined through the dependency checks and review discussed later.
Compose UoW programs with a Free Monad and Consequence
A Free Monad composes operations to be executed within UoW into a program description without executing them immediately. Types check operation inputs, outputs, and connection conditions; keeping the functions that construct the description pure avoids effects and hidden-state dependencies during composition. This combination applies both type-level connection guarantees and a structure supporting local reasoning through pure functions to programs containing external operations.
Incorporating Consequence’s composition rules into the operation description connects calculations and external operations through the same outcome and failure system. The Free Monad handles operation descriptions and composition; Consequence handles outcomes and failures. In the implementation, UnitOfWorkOp represents operations, Program represents the Free Monad program, and ConsequenceT incorporates Consequence’s outcome and error rules into that program.
The interpreter evaluates the program description, executes its operations through UoW’s shared path, and returns the outcome as Consequence. Tests check operation composition and actual responses. Runtime infrastructure, including asynchronous execution, communication, failure handling, and resource management, supports reactive characteristics; Episode 7 examines those mechanisms.
Typed operations are composed purely, Consequence handles outcomes and failures, and UoW manages execution. This division of responsibilities reduces the control logic that AI implements individually. Checks and review verify adherence to that division, making the combination a programming harness.
Check component structure and business meaning
Code conforming to types and operation rules is also checked for consistency with component responsibilities and requirements. CAR structural checks, dependency checks, tests, and model-based review cover conditions beyond those handled by language types.
Check deviations from component structure against CAR contracts
CAR packages contracts such as Component, Service, and Operation with implementations, dependencies, and documentation into an inspectable structure. car-lint checks mechanized rules for that structure and its public contracts, bringing AI-added code under component conformance checks. Requirements to fit the defined component structure extend the harness beyond producing type-correct functions.
textus-cbd-support supports reviews informed by component specifications, dependencies, and model information. Alongside car-lint’s structural checks, this information helps establish whether an implementation fits its component’s responsibilities.
Leave shared responsibilities to shared mechanisms
Checks also examine whether AI duplicates responsibilities already handled by shared mechanisms. Revalidating checked inputs or adding custom retries around infrastructure-managed processing can introduce unnecessary branches or duplicate execution. Input types and standard API contracts provide the criteria for this examination.
Dependency checks examine calls that bypass public APIs. Review examines whether added defensive processing is required by the business or duplicates guarantees provided by shared mechanisms. This verifies conformance to the prescribed implementation structure while retaining necessary business validation.
Check mechanical conformance and business meaning separately
A type-correct total calculation is still wrong for the business if its discount rate or rounding differs from requirements. Type checking examines values and connections, lint checks structural rules, tests check results for concrete inputs, and model-based review examines correspondence between requirements and design. Combining checks of different conditions covers errors beyond the scope of any one check.
Connect diagnostics to correction and limit diverging changes
Diagnostics from checks define the scope of correction and the conditions to recheck. Combining the selection of correction targets with verification after changes helps prevent AI-driven changes from diverging.
Correct the part responsible for a change
Corrections return to the responsible source: business meaning to the model, generated structure to generation rules, and specific processing to supplementary code. This prevents patches to generated output from being lost during regeneration and clarifies responsibility for changes.
After a model change, types and APIs are regenerated and compiled to locate incompatible connections. AI adapts supplementary code to the changed contract rather than weakening it to remove diagnostics.
Return diagnostics to local correction and escalate decisions
Compilation, lint, and focused tests provide diagnostics; the relevant code is corrected and the same conditions are rechecked. Giving AI reproducible diagnostics and verification conditions bounds the correction target.
When the cause remains unclear or a contract change is needed, the issue returns to design review or a responsible person with model information instead of accumulating more changes. Dividing responsibility between mechanical checks, semantic review, and human judgment helps prevent corrections from diverging.
Conclusion
Combining types, composition rules, shared infrastructure, and component checks guides AI implementation toward less error-prone structures and constrains both reuse and supplementary code. Using AI’s coding capabilities within this framework makes advanced techniques practical while reducing correction and repeated review, with the aim of achieving the required quality in less development time and at lower AI usage cost.
Episode 7 examines the runtime harness that supports authorization and resource management during execution.
References
Glossary
- Scala
-
Undefined
- SimpleModeling
-
SimpleModeling is a modeling-centered software development methodology and technology system for constructing a Domain Model from Knowledge, formalizing it in CML, realizing it as executable software through Cozy and AI, and running it on Textus.
- Model
-
A Model is an abstraction that represents a subject according to a particular Purpose and Concern so that it can be understood, reasoned about, evaluated, or constructed. It is not the subject itself; it preserves the elements, relationships, and meanings required for its purpose.
- deviation
-
The state in which a computed or observed value differs from a baseline or true value. Represents a measurable quantitative discrepancy.
- Dependency
-
In UML, a Dependency is a directed Relationship indicating that the specification or implementation of a client Model Element depends semantically or structurally on the definition of a supplier Model Element.
- Operation
-
In UML, an Operation is a Behavioral Feature of a Classifier that specifies the name, type, Parameters, and Constraints for invoking associated Behavior. The Operation specifies an invocation contract, while a Method or another Behavior realizes it.
- error
-
A generic term used broadly in practice. In software engineering, it is ambiguous and may denote bugs or failures in general. In SimpleModeling, Error is treated as a broad label, with specifics clarified as Mistake, Defect, Fault, Failure, or Deviation.
- CML (Cozy Modeling Language)
-
CML (Cozy Modeling Language) is the SimpleModeling formal modeling language for describing the Executable Model portion of an Object Model that connects to program generation and execution.
- Cozy
-
Cozy is the SimpleModeling toolchain that analyzes Models expressed in CML and other DSLs and transforms them into realization artifacts such as programs, configuration, and documentation.
- Textus
-
Textus is the runtime foundation for operating software realized through SimpleModeling. It provides execution, operational, and integration mechanisms shared by applications.
- Type
-
Undefined
- Constraint
-
In UML, a Constraint is a condition or restriction expressed in natural language or a machine-readable language to declare part of the Semantics of one or more Model Elements. Its evaluation yields a Boolean value and has no side effects.
- State
-
In UML, a State models a situation during which an invariant condition holds. The current State of an Object may determine accepted Events and Operations, applicable Constraints, and possible next Transitions.
- StateMachine
-
In UML, a StateMachine is a Behavior that expresses the event-driven Behavior of a system element by traversing a graph of States through Transitions triggered by Event occurrences.
- Behavior
-
In UML, Behavior is a specification of how its context Behaviored Classifier changes State over time. It may define possible executions, emergent Behavior, or a selected example of execution.
- verification
-
Verification is the activity of confirming that an implementation conforms to its specified design or requirements.
- defect
-
An imperfection or deficiency in a work product (designs, specifications, code, etc.). It does not meet requirements or specifications and requires repair or replacement. Defined in ISO/IEC 24765.
- monad
-
A monad is an abstraction for chaining computations in a context. It consists primarily of flatMap (or bind) and pure (or unit), allowing safe, composable expression of sequential operations, state handling, and error propagation in a functional style.
- applicative (applicative functor)
-
An applicative is an abstraction that allows applying a function in a context to a value in a context. It provides a way to combine independent computations via operations like pure, ap, or mapN, enabling parallel or independent evaluation.
- Execution Control
-
Undefined
- Cloud Native Component Framework (CNCF)
-
Cloud Native Component Framework (CNCF) is a framework for executing cloud application components using a single, consistent execution model. Centered on the structure of Component, Service, and Operation, it enables the same Operation to be reused across different execution forms such as command, server (REST / OpenAPI), client, and script. By centralizing quality attributes required for cloud applications—such as logging, error handling, configuration, and deployment—within the framework, components can focus on implementing domain logic. CNCF is designed as an execution foundation for literate model-driven development and AI-assisted development, separating what is executed from how it is invoked.
- internal DSL
-
An internal DSL is a domain-specific abstraction built within the syntax and type system of a host language. It allows leveraging existing tooling and guarantees type safety, often used in Scala via functions, type classes, macros, and extension methods.
- Persistence
-
Undefined
- Test
-
A Test is an activity and specification that executes or evaluates a subject under stated conditions and compares observed results with expected results or Constraints to check conformance to requirements or contracts.
- Communication
-
Undefined
- Responsibility
-
A Responsibility is an obligation stating what an Object or Role must know, decide, perform, or protect. It assigns ownership of rules and Behavior, not merely structural information.
- Component
-
A software construct that encapsulates well-defined responsibilities, contracts, and dependencies as a reusable and replaceable unit. In the logical model, it serves as an abstract structural unit; in the physical model, it corresponds to an implementation or deployment unit.
- validation
-
Validation is the activity of confirming that a system or product fulfills its intended use and stakeholder requirements.
- generated output
-
Artifacts produced through the knowledge-expression process of generative AI, including documents, code, summaries, and structured data.