9 Parser combinators

This chapter covers

  • An algebraic design approach to libraries
  • Primitives vs. higher-level combinators
  • Using combinators to achieve design goals
  • Improving library ease of use with syntactic sugar
  • Postponing combinator implementation by first focusing on algebra design

In this chapter, we work through the design of a combinator library for creating parsers. We’ll use JSON parsing as a motivating use case. Like chapters 7 and 8, this chapter is not so much about parsing as it is about providing further insight into the process of functional design.

What is a parser?

A parser is a specialized program that takes unstructured data (such as text or a stream of symbols, numbers, or tokens) as input and outputs a structured representation ...

Get Functional Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.