liveBook · Manning

Bottom

As explained in Functional Programming in Scala, Second Edition

Bottom is the semantic outcome of an expression that does not return a definite value because it diverges or throws an error.

Bottom is the semantic outcome of evaluating an expression that never returns a definite value because it runs forever or throws an error. The term makes divergence and failure part of reasoning about expression evaluation. section 5.1

Bottom clarifies strictness: a function is strict when applying it to any argument that evaluates to bottom also produces bottom. Nonstrict functions can avoid evaluating such arguments, using call-by-name parameters. section 5.1

Avoiding an unused bottom

A nonstrict conditional can select a safe branch without evaluating the other: `if2(false, sys.error("fail"), 3)` produces `3`. The error expression would evaluate to bottom if forced, but the unselected branch is never evaluated. section 5.1

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines bottom formally and connects it to strictness and call-by-name, without developing a broader theory of divergence.
Examples
Uses throwing conditionals, nonstrict if2 branches, short-circuit Boolean expressions, and repeated or cached by-name evaluation.
What it assumes
Assumes familiarity with Scala expressions and functions while introducing strictness, nonstrictness, and bottom terminology.
What you can do after
Evaluate how argument-strategy choices determine whether an expression reaches bottom.
How it connects
Connects bottom with strictness, nonstrict functions, call-by-name evaluation, and laziness.

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.