Appendix B: A Glossary for the Functional-Curious
Functional programming carries fifty years of vocabulary, some of it more intimidating than the ideas deserve. Working definitions, in plain terms, of every term this book uses.
Immutability. Values cannot be modified after creation. “Changing” something means computing a new value. See Part I.
Pure function. Output depends only on inputs; calling it causes nothing outside itself. The same call always returns the same answer.
Side effect. Anything a function does besides return a value: writing a file, sending a request, mutating shared state. In Mar, side effects are described by values (Cmd, Task) and performed by the runtime.
Referential transparency. The property that an expression can be replaced by its value without changing the program. A consequence of purity, and the reason refactoring pure code is safe.
Expression vs statement. An expression produces a value (if in Mar); a statement performs an action (if in most languages). Mar has only expressions.
Union type (also sum type, custom type, algebraic data type). A type whose values are one of several named cases, each optionally carrying data: type Status = Open | Assigned User | Closed.
Constructor. One of a union’s named cases (Assigned), usable both to build values and in patterns to take them apart.
Pattern matching. Inspecting a value’s shape with case, binding its parts as it matches. Checked for exhaustiveness at compile time.
Exhaustiveness. The compiler’s guarantee that a case handles every constructor. The mechanism that turns “add a new state” into a checklist of compile errors instead of runtime surprises.
Maybe a. The standard union for optional values: Just a or Nothing. Mar’s replacement for null, with the crucial difference that the type system tracks it.
Result e a. The standard union for fallible outcomes: Ok a or Err e. Mar’s replacement for exceptions.
Type inference (Hindley-Milner). The algorithm that deduces every expression’s type without annotations. You write types on top-level functions as documentation, not obligation.
Record. A value with named fields, structurally typed: { id : Int, name : String }.
Type alias. A name for a type, usually a record shape: type alias User = { ... }. Aliases describe; unions define.
MVU (Model-View-Update). The frontend architecture: one state value, a pure render function, a pure transition function, connected in a one-way loop by the runtime. Also called The Elm Architecture.
Model. The single immutable value holding all of a page’s state.
Msg. A page’s union of everything that can happen; the only input to update.
Cmd msg. A description of work the runtime should do, whose outcome returns as a message. The frontend’s effect type.
Sub msg. A standing declaration of interest in outside events (time, keys), recomputed from the Model. The frontend’s inbound channel.
Task a. A description of a computation that produces a value when the runtime runs it. The backend’s effect type; reaches the frontend only via Cmd.perform.
let <- (bind). Backend sugar for chaining Tasks: run the right-hand Task, name its result, continue. Mar’s cousin of await.
Managed effects. The umbrella doctrine: user code describes effects as values; the runtime performs them. The foundation under MVU, services, and the Repo.
Service. A typed contract for one client-server call, declared once (Service.declare VERB "/path") and imported by both halves. The frontend calls it; the backend implements it; the compiler keeps them agreeing.
Entity. A typed declaration of a database table, from which Mar derives the schema, migrations, codecs, and admin UI.
Repo. The small module of typed database operations (all, findById, findBy, create, update, deleteById), each returning a Task.
Codec. The encoding between Mar values and the wire or database formats. Fully derived from types in Mar; user code never writes one.
Decimal. Mar’s exact base-10 number type (19.99 means 19.99). Sums and products never round; division returns a Decimal.Division that you resolve by naming a rounding mode and scale.
Fixed-point arithmetic. Representing fractional quantities as scaled integers (cents, sixteenths of a pixel). How Mar’s games run fractional physics on pure Ints.
Structural sharing. The implementation trick that makes immutability cheap: a “modified” value reuses the unchanged parts of the original, which is safe precisely because nothing can mutate them.
Draw list. The canvas’s frame description: an immutable list of shapes, rebuilt each frame from the Model, rendered by the runtime.
Time-travel debugging. Scrubbing an app backward and forward through its history of Models. Possible because states are immutable values and every change came through update.
Sashimono. Japanese joinery without nails or glue; each piece is shaped to fit the others. Mar’s founding metaphor: replace the glued seams between stack layers with compiler-checked joints.