Publications [000D]
Published papers
Reference. You Could Have Invented Fenwick Trees (Functional Pearl) [yorgey-fenwick-2025]
Fenwick trees, also known as binary indexed trees, are a clever solution to the problem of maintaining a sequence of values while allowing both updates and range queries in sublinear time. Their implementation is concise and efficient—but also somewhat baffling, consisting largely of nonobvious bitwise operations on indices. We begin with segment trees, a much more straightforward, easy-to-verify, purely functional solution to the problem, and use equational reasoning to explain the implementation of Fenwick trees as an optimized variant, making use of a Haskell EDSL for operations on infinite two's complement binary numbers.
See also this blog post summary. Published as part of a special issue on program calculation.
@article{yorgey-2025,
title = {You could have invented Fenwick trees},
volume = {35},
doi = {10.1017/S0956796824000169},
journal = {Journal of Functional Programming},
author = {Yorgey, Brent},
year = {2025},
pages = {e3}
}Reference. Disco: A Functional Programming Language for Discrete Mathematics [yorgey-disco-2023]
Disco is a pure, strict, statically typed functional programming language designed to be used in the setting of a discrete mathematics course. The goals of the language are to introduce students to functional programming concepts early, and to enhance their learning of mathematics by providing a computational platform for them to play with. It features mathematically-inspired notation, property-based testing, equirecursive algebraic types, subtyping, built-in list, bag, and finite set types, a REPL, and student-focused documentation. Disco is implemented in Haskell, with source code available on GitHub, and interactive web-based REPL available through replit.
@Inproceedings{yorgey-disco-2023,
author = {Yorgey, Brent A.},
year = {2023},
title = {Disco: A Functional Programming Language for Discrete Mathematics},
editor = {Machkasova, Elena},
booktitle = {{\rm Proceedings Twelfth International Workshop on}
Trends in Functional Programming in Education,
{\rm Boston, Massachusetts, USA, 12th January 2023}},
series = {Electronic Proceedings in Theoretical Computer Science},
volume = {382},
publisher = {Open Publishing Association},
pages = {64-81},
doi = {10.4204/EPTCS.382.4},
}Reference. What's the Difference? A Functional Pearl on Subtracting Bijections [yorgey-foner-2018]
It is a straightforward exercise to write a program to "add" two bijections—resulting in a bijection between two sum types, which runs the first bijection on elements from the left summand and the second bijection on the right. It is much less obvious how to "subtract" one bijection from another. This problem has been studied in the context of combinatorics, with several computational principles known for producing the "difference" of two bijections. We consider the problem from a computational and algebraic perspective, showing how to construct such bijections at a high level, avoiding pointwise reasoning or being forced to construct the forward and backward directions separately—without sacrificing performance.
@article{yorgey-foner-2018,
author = {Yorgey, Brent A. and Foner, Kenneth},
title = {What's the Difference? A Functional Pearl on Subtracting Bijections},
journal = {Proc. ACM Program. Lang.},
issue_date = {September 2018},
volume = {2},
number = {ICFP},
month = jul,
year = {2018},
issn = {2475-1421},
pages = {101:1--101:21},
articleno = {101},
numpages = {21},
url = {http://doi.acm.org/10.1145/3236796},
doi = {10.1145/3236796},
acmid = {3236796},
publisher = {ACM},
address = {New York, NY, USA},
keywords = {bijection, difference},
}Reference. How to Twist Pointers without Breaking Them [chauhan-kurur-yorgey-2016]
Using the theory of monoids and monoid actions, we give a unified framework that handles three common pointer manipulation tasks, namely, data serialisation, deserialisation, and memory allocation. Our main theoretical contribution is the formulation of the notion of a twisted functor, a generalisation of the semi-direct product construction for monoids. We show that semi-direct products and twisted functors are particularly well suited as an abstraction for many pointer manipulation tasks.
We describe the implementation of these abstractions in the context of a cryptographic library for Haskell. Twisted functors allow us to abstract all pointer arithmetic and size calculations into a few lines of code, significantly reducing the opportunities for buffer overflows.
@inproceedings{chauhan-kurur-yorgey-2016,
author = {Chauhan, Satvik and Kurur, Piyush P. and Yorgey, Brent A.},
title = {How to Twist Pointers Without Breaking Them},
booktitle = {Proceedings of the 9th International Symposium on Haskell},
series = {Haskell 2016},
year = {2016},
isbn = {978-1-4503-4434-0},
location = {Nara, Japan},
pages = {51--61},
numpages = {11},
url = {http://doi.acm.org/10.1145/2976002.2976004},
doi = {10.1145/2976002.2976004},
acmid = {2976004},
publisher = {ACM},
address = {New York, NY, USA},
keywords = {applicative functor, monoid, monoid action, pointer, semi-direct product},
}Reference. Polynomial Functors Constrained by Regular Expressions [piponi-yorgey-2015]
We show that every regular language, via some DFA which accepts it, gives rise to a homomorphism from the semiring of polynomial functors to the semiring of n \times n matrices over polynomial functors. Given some polynomial functor and a regular language, this homomorphism can be used to automatically derive a functor whose values have the same shape as those of the original functor, but whose sequences of leaf types correspond to strings in the language.
The primary interest of this result lies in the fact that certain regular languages correspond to previously studied derivative-like operations on polynomial functors, which have proven useful in program construction. For example, the regular language a^* h a^* yields the derivative of a polynomial functor, and b^* h a^* its dissection. Using our framework, we are able to unify and lend new perspective on this previous work. For example, it turns out that dissection of polynomial functors corresponds to taking divided differences of real or complex functions, and, guided by this parallel, we show how to generalize binary dissection to n-ary dissection.
@inproceedings{piponi-yorgey-2015,
title={Polynomial functors constrained by regular expressions},
author={Piponi, Dan and Yorgey, Brent A.},
booktitle={International Conference on Mathematics of Program Construction},
pages={113--136},
year={2015},
organization={Springer}
}Reference. Monoids: Theme and Variations (Functional Pearl) [yorgey-monoids-2012]
The monoid is a humble algebraic structure, at first glance even downright boring. However, there's much more to monoids than meets the eye. Using examples taken from the diagrams vector graphics framework as a case study, I demonstrate the power and beauty of monoids for library design. The paper begins with an extremely simple model of diagrams and proceeds through a series of incremental variations, all related somehow to the central theme of monoids. Along the way, I illustrate the power of compositional semantics; why you should also pay attention to the monoid's even humbler cousin, the semigroup; monoid homomorphisms; and monoid actions.
@inproceedings{10.1145/2364506.2364520,
author = {Yorgey, Brent A.},
title = {Monoids: Theme and Variations (Functional Pearl)},
year = {2012},
isbn = {978-1-4503-1574-6},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/2364506.2364520},
doi = {10.1145/2364506.2364520},
booktitle = {Proceedings of the 2012 Haskell Symposium},
pages = {105--116},
numpages = {12},
keywords = {monoid action, monoid, homomorphism, edsl},
location = {Copenhagen, Denmark},
series = {Haskell '12}
}Reference. Giving Haskell a Promotion [yorgey-promotion-2012]
Static type systems strive to be richly expressive while still being simple enough for programmers to use. We describe an experiment that enriches Haskell's kind system with two features promoted from its type system: data types and polymorphism. The new system has a very good power-to-weight ratio: it offers a significant improvement in expressiveness, but, by re-using concepts that programmers are already familiar with, the system is easy to understand and implement.
@inproceedings{Yorgey:2012:GHP:2103786.2103795,
author = {Yorgey, Brent A. and Weirich, Stephanie and Cretin, Julien and Peyton Jones, Simon and Vytiniotis, Dimitrios and Magalh\~{a}es, Jos{\'e} Pedro},
title = {Giving Haskell a Promotion},
booktitle = {Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation},
series = {TLDI '12},
year = {2012},
isbn = {978-1-4503-1120-5},
location = {Philadelphia, Pennsylvania, USA},
pages = {53--66},
numpages = {14},
url = {http://doi.acm.org/10.1145/2103786.2103795},
doi = {10.1145/2103786.2103795},
acmid = {2103795},
publisher = {ACM},
address = {New York, NY, USA},
keywords = {haskell, kinds, polymorphism, promotion},
}Reference. Binders Unbound [weirich-yorgey-sheard-2011]
Implementors of compilers, program refactorers, theorem provers, proof checkers, and other systems that manipulate syntax know that dealing with name binding is difficult to do well. Operations such as α-equivalence and capture-avoiding substitution seem simple, yet subtle bugs often go undetected. Furthermore, their implementations are tedious, requiring "boilerplate" code that must be updated whenever the object language definition changes.
Many researchers have therefore sought to specify binding syntax declaratively, so that tools can correctly handle the details behind the scenes. This idea has been the inspiration for many new systems (such as Beluga, Delphin, FreshML, FreshOCaml, Cαml, FreshLib, and Ott) but there is still room for improvement in expressivity, simplicity and convenience.
In this paper, we present a new domain-specific language, Unbound, for specifying binding structure. Our language is particularly expressive - it supports multiple atom types, pattern binders, type annotations, recursive binders, and nested binding (necessary for telescopes, a feature found in dependently-typed languages). However, our specification language is also simple, consisting of just five basic combinators. We provide a formal semantics for this language derived from a locally nameless representation and prove that it satisfies a number of desirable properties.
We also present an implementation of our binding specification language as a GHC Haskell library implementing an embedded domain specific language (EDSL). By using Haskell type constructors to represent binding combinators, we implement the EDSL succinctly using datatype-generic programming. Our implementation supports a number of features necessary for practical programming, including flexibility in the treatment of user-defined types, best-effort name preservation (for error messages), and integration with Haskell's monad transformer library.
@inproceedings{weirich-yorgey-sheard-2011-unbound,
author = {Weirich, Stephanie and Yorgey, Brent A. and Sheard, Tim},
title = {Binders Unbound},
booktitle = {Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming},
series = {ICFP '11},
year = {2011},
isbn = {978-1-4503-0865-6},
location = {Tokyo, Japan},
pages = {333--345},
numpages = {13},
url = {http://doi.acm.org/10.1145/2034773.2034818},
doi = {10.1145/2034773.2034818},
acmid = {2034818},
publisher = {ACM},
address = {New York, NY, USA},
keywords = {generic programming, haskell, name binding, patterns},
}Reference. Species and Functors and Types, Oh My! (Functional Pearl) [yorgey-species-2010]
- September 30, 2010
- Brent A. Yorgey
- Haskell '10: Haskell Symposium
- 10.1145/1863523.186354
- Video
The theory of combinatorial species, although invented as a purely mathematical formalism to unify much of combinatorics, can also serve as a powerful and expressive language for talking about data types. With potential applications to automatic test generation, generic programming, and language design, the theory deserves to be much better known in the functional programming community. This paper aims to teach the basic theory of combinatorial species using motivation and examples from the world of functional programming. It also introduces the species library, available on Hackage, which is used to illustrate the concepts introduced and can serve as a platform for continued study and research.
@inproceedings{yorgey-2010-species,
author = {Yorgey, Brent A.},
title = {Species and functors and types, oh my!},
booktitle = {Proceedings of the third ACM Haskell symposium on Haskell},
series = {Haskell '10},
year = {2010},
isbn = {978-1-4503-0252-4},
location = {Baltimore, Maryland, USA},
pages = {147--158},
numpages = {12},
url = {http://doi.acm.org/10.1145/1863523.1863542},
doi = {http://doi.acm.org/10.1145/1863523.1863542},
acmid = {1863542},
publisher = {ACM},
address = {New York, NY, USA},
keywords = {algebraic data types, combinatorial species},
}Dissertation
Reference. Combinatorial Species and Labelled Structures [yorgey-species-2015]
- October 14, 2014
- Brent A. Yorgey
- Doctoral dissertation, University of Pennsylvania
- Slides
The theory of combinatorial species was developed in the 1980s as part of the mathematical subfield of enumerative combinatorics, unifying and putting on a firmer theoretical basis a collection of techniques centered around generating functions. The theory of algebraic data types was developed, around the same time, in functional programming languages such as Hope and Miranda, and is still used today in languages such as Haskell, the ML family, and Scala. Despite their disparate origins, the two theories have striking similarities. In particular, both constitute algebraic frameworks in which to construct structures of interest. Though the similarity has not gone unnoticed, a link between combinatorial species and algebraic data types has never been systematically explored. This dissertation lays the theoretical groundwork for a precise—and, hopefully, useful—bridge bewteen the two theories. One of the key contributions is to port the theory of species from a classical, untyped set theory to a constructive type theory. This porting process is nontrivial, and involves fundamental issues related to equality and finiteness; the recently developed homotopy type theory is put to good use formalizing these issues in a satisfactory way. In conjunction with this port, species as general functor categories are considered, systematically analyzing the categorical properties necessary to define each standard species operation. Another key contribution is to clarify the role of species as labelled shapes, not containing any data, and to use the theory of analytic functors to model labelled data structures, which have both labelled shapes and data associated to the labels. Finally, some novel species variants are considered, which may prove to be of use in explicitly modelling the memory layout used to store labelled data structures.
@phdthesis{yorgey-2014-thesis,
author = {Yorgey, Brent A.},
school = {University of Pennsylvania},
year = {2014},
title = {Combinatorial Species and Labelled Structures}
}Books
Presentations
Reference. Haskell for Competitive Programming (invited keynote) [yorgey-zurihac-2025]
- June 9, 2025
- Brent A. Yorgey
- ZuriHac 2025
- Video
Over the past ten years, I have solved over 1700 competitive programming problems in Haskell, just for fun (as well as a few that were not fun). I will give a brief introduction to competitive programming and show off some examples demonstrating the unique benefits of Haskell in this context. We will then have a miniature programming contest, open to all—only Haskell allowed!
Reference. Idiomatic Inference for DSLs [idiomatic-inference-PLV]
- January 30, 2025
- Brent A. Yorgey
- Portland State University PLV seminar
- Slides
McBride and Paterson's idioms, or applicative functors, are a well-known abstraction defining function application in some ambient effectful context. It would often be useful, especially in the context of designing domain-specific languages, to infer such "idiomatic'' application, allowing the programmer to use plain function application syntax—but only when doing so is unambiguous. I will present work in progress characterizing the conditions necessary for this to be possible.
Reference. The Joy of Building (Functional) Languages (invited keynote) [joy-functional-haskell]
- September 6, 2024
- Brent A. Yorgey
- Haskell '24: Haskell Symposium
- Slides
- Video
For almost as long as I can remember, all my best projects—the ones that I’m proudest of, the ones that have been the most fruitful and brought me the most joy—have all centered around building some kind of language. Perhaps I am just weird, but I think there is something uniquely joyful about not just expressing oneself, but creating a whole new means of expression for oneself and others. I will take you on a tour of some of my most interesting and joyful language-building projects (some of which you have probably heard of, some of which you definitely haven’t), and then we will build a language together!
Reference. Competitive Programming in Haskell [comprog-haskell-love]
- September 10, 2021
- Brent A. Yorgey
- Haskell Love
- Video
Competitive programming is an exciting mind sport where competitors race to solve difficult programming tasks as quickly as possible, either individually or as part of a team. It requires sharp problem-solving skills, broad knowledge of algorithms and data structures, and (often) developing a good library of reusable code components ahead of time. Most serious competitive programmers use C++, but this is an arena where Haskell can shine: Haskell's strong type system helps prevent stupid mistakes made in the heat of the moment, and its capability for abstraction allows us to develop versatile libraries and solve problems using a minimum of boilerplate. In this talk, I will livecode a solution to a representative challenge, showing off techniques and libraries along the way.
I will also highlight some areas needing work. In some cases, in order to fit within the time limit imposed by the creators of a problem, it is necessary to write code that runs within a small constant multiple of the time taken by a C++ solution. This is possible but difficult; the name of the game is to create libraries of algorithms and data structures that are highly optimized internally but present a flexible and idiomatic interface suitable for use in a contest.
I hope that Haskellers of all skill levels will be able to take away something new, and that some will be convinced to take up a new hobby, or contribute some code!
Reference. Graph Coloring with a SAT Solver [yorgey-graph-coloring-SAT-CCSC]
- April 6, 2018
- Brent A. Yorgey
- CCSC Mid-South
Reference. Explaining Type Errors [yorgey-eisenberg-eades-errors-OBT]
- January 13, 2018
- Brent A. Yorgey, Richard Eisenberg, Harley Eades
- OBT '18: Off The Beaten Track
- Slides
Every beginning student of programming—that is, every student with the ill fortune of having a language with a static type system foisted upon them by a well-intentioned yet sadistic instructor—is well-acquainted with the Dreaded Type Error Message. Why do type error messages have to be so terrifying? Can’t we do a better job explaining type errors to programmers?
We propose two interrelated theses:
- We ought to move away from static error “messages” and towards interactive error explanations.
- We ought to consider the problem of generating error explanations in a more systematic, disciplined, and formal way. Explaining errors to users shouldn’t just be relegated to the status of an “engineering issue”, but ought to have all the tools of programming language theory and practice applied to it.
Reference. Diagrams: A Functional EDSL for Vector Graphics [yates-yorgey-2015]
Diagrams is a domain-specific language for creating vector graphics. We will give a short diagrams tutorial/demo, particularly highlighting the power of a functional, embedded domain-specific language.
@inproceedings{yates-yorgey-2015,
author = {Yates, Ryan and Yorgey, Brent A.},
title = {Diagrams: a functional EDSL for vector graphics},
year = {2015},
isbn = {9781450338066},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/2808083.2808085},
doi = {10.1145/2808083.2808085},
abstract = {},
booktitle = {Proceedings of the 3rd ACM SIGPLAN International Workshop on Functional Art, Music, Modelling and Design},
pages = {4–5},
numpages = {2},
keywords = {EDSL, Haskell, diagrams, vector},
location = {Vancouver, BC, Canada},
series = {FARM 2015}
}Reference. Diagrams: Declarative Vector Graphics in Haskell [yorgey-diagrams-NYHUG-2013]
- November 20, 2013
- Brent A. Yorgey
- New York Haskell Users' Group
- Slides
- Video
Reference. Trees and Things (with Semirings!) [yorgey-trees-semirings]
- October 29, 2013
- Brent A. Yorgey
- Houghton College
Reference. Functional Active Animation [yorgey-active-2013]
Reference. Embedded, functional, compositional drawing [yorgey-compositional-drawing-2012]
- April 13, 2012
- Brent A. Yorgey
- Williams College
Reference. Typed type-level programming with GHC [yorgey-type-level-HIW-2010]
Reference. Random testing—and beyond! with combinatorial species [yorgey-species-2009]
- November 24, 2009
- Brent A. Yorgey
- University of Kansas
- Slides
Reference. Executable Mathematics: a Whirlwind Introduction to Haskell [yorgey-mathematics-haskell]
- June 8, 2008
- Brent A. Yorgey
- Williams College
Reference. xmonad: a Haskell Success Story [yorgey-xmonad-FringeDC]
- March 22, 2008
- Brent A. Yorgey
- FringeDC
- Slides