{
  "id": 7965486,
  "title": "Tilia—a new formatter for Haskell",
  "url": "https://urgent.news/2026/09/17/tilia-a-new-formatter-for-haskell",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-17T04:17:44.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://markkarpov.com/post/announcing-tilia.html"
  },
  "original_language": "en",
  "account": "Haskell is a notoriously challenging programming language to format due to its complex core parsing and printing mechanisms. Recent advancements in ghc-lib-parser have made this process somewhat more manageable, but three significant hurdles still remain. Tilia, a fresh formatter developed from scratch, seeks to address all three challenges in a systematic manner. This article explores Tilia's approach to solving problems related to operator fixities and CPP (Conditional Preprocessor) support.\n\nHaskell's custom operator fixities pose a considerable formatting challenge. Traditionally, there are two ways to discover the precedence of operators in a given chain: manual discovery and dependency-based discovery. The former approach has not been widely explored, while the latter relies on parsing the Haskell source code. Due to the complexities involved, Tilia opts for a dependency-based approach to discover operator fixities.\n\nFor external dependencies, Tilia primarily leverages the information provided by GHC's compilation process. This method simplifies the task, as Haskell already compiles the package, enabling Tilia to avoid dealing with CPP and other intricacies. However, consuming sources directly necessitates addressing these additional challenges.\n\nOne notable aspect of Tilia is its handling of operator names that are not immediately apparent from an import list. For instance, the data constructor \":|\" of the \"NonEmpty\" type is not explicitly mentioned in its import list. To address this, Tilia must track the re-export chains and handle potential ambiguity by reporting it when necessary.\n\nCPP support is another crucial aspect tackled by Tilia. Implementing CPP support required extensive research into papers on parsing and conditional compilation, such as SuperC and TypeChef. The chosen approach involves generating a document representation with an n-ary choice node to accommodate multiple alternatives. This representation enables Tilia to merge conflicting directives and maintain format consistency.\n\nIn summary, Tilia is a new Haskell formatter designed to overcome the challenges posed by operator fixities and CPP support. By adopting a dependency-based approach and implementing a novel CPP parsing strategy, Tilia aims to provide a more consistent and accurate formatting experience for Haskell code.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}