liveBook · Manning

Empty

As explained in Learn Haskell by Example

empty is the Alternative operation that represents failure or the identity element for applicative choice.

empty is the failure value for Alternative choice. As the identity element of (<|>), it always fails without consuming input, so another alternative can be tried. section 12.1.4

An empty parser alternative

A custom Parser defines empty as Parser $ \_ -> Left "empty alternative". Combined with (<|>), a failed parser retries from the original input; if every alternative fails, the errors are combined.

How Learn Haskell by Example covers it

How deep it goes
Defines identity and failure semantics, then implements empty in a custom parser without developing broader type-class theory.
Examples
Demonstrates empty through a custom Parser instance and GHCi choices between string parsers.
What it assumes
Assumes familiarity with Applicative and introduces Alternative through parser choice and the failure behavior of Maybe.
What you can do after
Build it from scratch by defining an always-failing empty parser and combining it with alternative parsers.
How it connects
Connects Alternative with Applicative, (<|>), parser rollback, Maybe, and error-message modification.

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.