distributors: Unifying Parsers, Printers & Grammars

[ bsd3, library, optics, parsing, profunctors ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.2.0.0, 0.2.0.1, 0.3.0.0
Change log CHANGELOG.md
Dependencies adjunctions (>=4.4 && <5), base (>=4.15 && <5), bifunctors (>=5.5 && <6), bytestring (>=0.11 && <1), containers (>=0.6 && <1), contravariant (>=1.5 && <2), distributive (>=0.6 && <1), lens (>=5.0 && <6), MemoTrie (>=0.6 && <1), mtl (>=2.2 && <3), profunctors (>=5.6 && <6), tagged (>=0.8 && <1), template-haskell (>=2.17 && <3), text (>=2 && <3), th-abstraction (>=0.4 && <1), vector (>=0.12 && <1), witherable (>=0.4 && <1) [details]
License BSD-3-Clause
Copyright 2026 Eitan Chatav
Author Eitan Chatav
Maintainer eitan.chatav@gmail.com
Uploaded by echatav at 2026-02-06T00:48:45Z
Category Profunctors, Optics, Parsing
Home page https://github.com/morphismtech/distributors#readme
Bug tracker https://github.com/morphismtech/distributors/issues
Source repo head: git clone https://github.com/morphismtech/distributors
Distributions NixOS:0.2.0.1
Downloads 151 total (17 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for distributors-0.3.0.0

[back to package description]

Distributors

Unifying Parsers, Printers & Grammars

GithubWorkflowCI

Github

Hackage

YouTube

This library provides mathematically inspired abstractions for coders to write parsers that can also be inverted to printers.

introduction

The term "distributor" is a synonym for "profunctor". Jean Bénabou who invented the term and originally used “profunctor,” then preferred “distributor”, which is supposed to carry the intuition that a distributor generalizes a functor in a similar way to how a distribution generalizes a function.

Bénabou in his time introduced the notions of enriched categories, bicategories as well as distributors and invented the term monad. He was lost to us on 11, February 2022 and this library is dedicated to his memory.

Since "profunctor" became the standard nomenclature, we reappropriate "distributor" to describe a profunctor on a distributive category.

This library provides a study of distributor theory and optics, and their application to invertible grammar theory.

previous work

The results concerning invertible parsers are a profunctorial interpretation of Invertible Syntax Descriptions by Tillman Rendel & Klaus Ostermann.

While Distributors in the library are lax distributive endoprofunctors, a mathematical treatment of strong (i.e. with invertible structure morphisms) distributors is given by Travis Squires in Profunctors and Distributive Categories.

The idea for unifying Backus-Naur grammars with parsers comes from Joachim Breitner in a post Showcasing Applicative.

The idea for using monadic profunctors for reversible context-free grammars comes from Li-Yao Xia, in some posts and a paper but particularly this post on Monadic profunctors for bidirectional programming.

The person deserving the most credit for bringing the power of optics to programming, with his lens library, is Ed Kmett, to whom I am very grateful for teaching me a lot.

None of the ideas in this library are particularly original and a lot of related ideas have been explored, in Tom Ellis' product-profunctors as well as Sjoerd Visscher's one-liner and more. Such explorations are not limited to Haskell. Brandon Williams and Stephen Celis' excellent swift-parsing was also influenced by invertible parser theory.

Some optics in this library are grates, a new kind of optic, discovered by Russel O'Connor and James Deikun; monocles which are studied by Alexandre Garcia de Oliveira, Mauro Jaskelioff, and Ana Cristina Vieira de Melo in On Structuring Functional Programs with Monoidal Profunctors; and withers, discovered by Chris Penner in Composable filters using Witherable optics.

contributing

Contributors are welcome. The Issues page is a good place to communicate.