# Fluent APIs in Functional Languages (full version)

**Authors:** Ori Roth, Yossi Gil  
**arXiv:** [2211.01473](https://arxiv.org/abs/2211.01473)  
**Date:** 2022-11-02  
**Summary page:** https://www.summarizepaper.com/en/arxiv-id/2211.01473v2/

## Key points

- The paper presents a methodology for creating smart and elegant APIs in functional programming languages.
- The approach enforces the API protocol or DSL syntax at compile time by performing language recognition at the type level.
- Parametric polymorphism and type inference are used to create functional fluent APIs that support all regular and deterministic context-free API protocols and beyond.
- An HTML EDSL is embedded as an SML expression using their EDSL, which closely resembles HTML with minimal syntactic overhead imposed by the host programming language.
- The proposed methodology does not rely on a specific language feature, making it compatible with most statically-typed functional languages.
- It uses automata specifications for API protocols instead of external tools or dedicated language features.
- By embedding DSLs as fluent APIs, developers can leverage the power of statically-typed functional languages while ensuring that their code adheres to strict protocol requirements at compile time.

## Summary

This paper presents a methodology for creating smart and elegant APIs in functional programming languages. The proposed approach enforces the API protocol or DSL syntax at compile time by performing language recognition at the type level. Unlike traditional fluent API designs that rely on function overloading, this methodology uses parametric polymorphism and type inference to create functional fluent APIs that support all regular and deterministic context-free API protocols and beyond. The authors demonstrate their approach by embedding an HTML document as an SML expression using their EDSL. This HTML EDSL is both elegant and smart, closely resembling HTML with minimal syntactic overhead imposed by the host programming language. The EDSL coerces the SML compiler into enforcing HTML's syntax, ensuring that invalid webpages do not compile. The tags must appear in the correct order, every opening tag must have a matching closing tag, and all table rows must have the same number of columns. The proposed methodology does not rely on a specific language feature, making it compatible with most statically-typed functional languages. It also differs from other approaches such as typestates or static analysis methods for enforcing API protocols specified by context-free grammars, as it uses automata specifications for API protocols instead of external tools or dedicated language features. Overall, this paper offers valuable insights into creating functional fluent APIs using parametric polymorphism and type inference instead of overloading. By embedding DSLs as fluent APIs, developers can leverage the power of statically-typed functional languages while ensuring that their code adheres to strict protocol requirements at compile time.
