liveBook · Manning

Numbered line

As explained in Learn Haskell by Example

A numbered line is a line of text represented together with its associated line-numbering information.

A numbered line pairs a text line with an optional line number. The number is optional because some lines may be displayed without numbering, while the text remains part of the value. section 4.1.1

In Haskell, represent one numbered line as (Maybe Int, String), and represent a sequence as a list of those pairs. Maybe encodes the difference between a numbered line and an intentionally unnumbered line. section 4.1.1

Numbering behavior separates two decisions:

  • Predicates make policies such as numbering all lines, skipping empty lines, or counting and numbering different sets configurable. section 4.1.1

Mixed numbering

A value such as [(Just 1, "First line"), (Nothing, ""), (Just 2, "Second line")] preserves the empty line while indicating that it should receive no printed number.

How Learn Haskell by Example covers it

How deep it goes
Defines the representation and construction policies, then renders values, but stops short of broader performance treatment.
Examples
Uses numbered lists, skipped empty lines, optional-number pairs, and padded human-readable output.
What it assumes
Assumes lists and strings while teaching Maybe as an optional-value type.
What you can do after
Build it from scratch as a Haskell data representation and transform it into configurable numbered-line output.
How it connects
Connects Maybe, lists, predicates, higher-order functions, pure functions, and library modules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.