PeaBox Lab › PeaLang › Learn › Chapter 26 › Lesson 2

Part IV — Expert Production Engineering · Chapter 26 · Lesson 2 of 6 · 2 min read

Lesson 2: Typed Multi-Module PeaLang Application

Lesson level: Expert

Purpose: A typed modular application remains safe only when validation, policy, and host authority stay separate.

Learning Objectives

2.1 Concepts

Separate pure policy, validation, reporting, and host adapters into modules. Use explicit exports, documented parameter and return contracts, and portable data. Type annotations support analysis but are erased before runtime parsing; they do not validate untrusted requests automatically. Keep deterministic rule precedence and related outputs together, and run the appropriate source, type, semantic, and project checks.

2.2 Annotated Example

Illustrative project layout: src/validation.pea validates types and ranges; src/policy.pea evaluates approved precedence; src/report.pea shapes safe output; tests/ contains native fixtures; the host handles I/O. Use function, not fn, and import a quoted module path. Export a function by naming it in a separate export statement. Choose actual helper spellings from the installed reference rather than creating new APIs in the guide.

2.3 Guided Practice

Trace one security-relevant case, one exact impact threshold, and one malformed record through the validation and policy boundaries. Explain why a valid type is not proof of a valid business range.

2.4 Common Mistakes

Do not leak unexported names, mix secrets into modules, shadow policy constants, or confuse static annotations with runtime validation.

2.5 Hands-On Lab

Deliverable: Stage implementation or design, contract, fixture evidence, and unresolved items. Do not advance a failed mandatory contract as passed.

2.6 Review Questions

Why are annotations insufficient at the host boundary? Which module owns policy precedence? How are exports declared?

2.7 Applied Challenge

Change one approved policy threshold in a test branch and prove that only the expected fixture decisions change.

Lesson Summary

A typed modular application remains safe only when validation, policy, and host authority stay separate.

Lesson status: Draft complete; ready for review.

← Previous Next →