liveBook · Manning

Algebraic law

An algebraic law is a general equation or behavioral property that an operation or implementation is expected to satisfy for applicable values.

How 3 Manning books explain it

Data-Oriented Programming in Java

An algebraic property is a characteristic describing how an operation behaves under operand order, grouping, and relationships between inputs and outputs.

How it is used
Defines correctness contracts for domain operations and turns them into tests over all relevant states.
How deep it goes
Explains universal assertions, associativity, commutativity, ordering, monotonicity, and exhaustive Java checks; defers no single required implementation.
Examples
Uses conflicting RawData merges, subtraction and floating-point addition, generated Optional states, cart invariants, and task lifecycle transitions.
What you can do after
Evaluate/understand operations by stating laws precisely and verifying invariants across generated states or external dependencies.

Read how Data-Oriented Programming in Java explains algebraic law →

Functional Programming in Scala, Second Edition

A law is a general equation or behavioral property that operations or their implementations are expected to satisfy.

How it is used
Constrain API operations and supply properties for reasoning, algebraic design, and property-based testing.
How deep it goes
Develops concrete mapping and flatMap equations, derives identity, and proves associativity for Option through case expansion.
Examples
Uses Par mapping, ExecutorService result comparison, Option cases, parser identities, and generated Order values.
What you can do after
Evaluate/understand whether alternative implementations preserve stated API behavior and derive reusable operations from lawful primitives.

Read how Functional Programming in Scala, Second Edition explains algebraic law →

Learn Haskell by Example

Property is the QuickCheck type representing a testable property, including properties augmented with conditions or classifications.

How it is used
Expresses implementation invariants as generated tests that search for counterexamples.
How deep it goes
Defines Bool and Property forms, demonstrates modifiers and shrinking, and defers custom Testable instances.
Examples
Uses sorted lists, rot13 symmetry, alphabet closure, and arithmetic properties in test suites.
What you can do after
Apply it via QuickCheck to run generated invariant checks and organize prop_-named tests into Stack suites.

Read how Learn Haskell by Example explains algebraic law →

Also covered in

What to know first

Related concepts

Questions about algebraic law

What is algebraic law?

An algebraic law is a general equation or behavioral property that an operation or implementation is expected to satisfy for applicable values.

Which Manning books explain algebraic law?

Data-Oriented Programming in Java, Functional Programming in Scala, Second Edition and Learn Haskell by Example.

What should I know before learning algebraic law?

Manning books that teach algebraic law usually introduce parallelism, state, option and list first.

What is algebraic law part of?

Algebraic law is part of monad. A monad is a programming abstraction that provides operations for sequencing computations while encapsulating and preserving their computational context.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.