- Home
- Code Formatting Tools
- Fourmolu
Fourmolu
What it is
Fourmolu is a configurable formatter for Haskell source code and a fork of Ormolu. It uses GHC's parser and aims for minimal diffs, idempotent formatting, and support for large projects and modern Haskell dialects. Settings can go in a fourmolu.yaml file or be passed as command-line options. Controls include indentation, line length, import grouping, record layout, Haddock comments, Unicode output, and operator fixities. Fourmolu can find a source file's Cabal file and use its default extensions and dependencies to help determine fixities. Magic comments can skip selected code, and command-line options can target a line region. The project provides an interactive browser demo with configurable formatting and program options. Editor integration is documented through Haskell Language Server. Installation instructions cover GHCup, Cabal, Stack, and dotslash; the README also recommends the run-fourmolu GitHub Action for CI. Its listed current release is v0.21.0.0. CPP support is experimental and works only in simple cases where conditionals surround top-level declarations. Output always uses LF line endings, so check mode can fail on files with CRLF endings. Fourmolu is open source and free.
For and against
For
- Configures formatting through YAML or command-line options.
- Includes an interactive browser demo.
- Integrates with Haskell Language Server.
- Can use Cabal settings to inform operator fixities.
- Supports selective formatting by comments or line region.
Against
- CPP support is experimental and limited to simple cases.
- Always outputs LF line endings.
- Check mode can fail on CRLF files.
The verdict
Fourmolu offers configurable Haskell formatting with browser, editor, and CI options. Projects relying on CPP or CRLF files should account for its listed limitations.
Who it suits
Fourmolu suits Haskell developers who want configurable formatting in command-line, browser, editor, or CI workflows. Its Cabal awareness and selective formatting options may be useful in projects with project-specific extensions or sections to exclude.
Plans and prices
Fourmolu
Open-source Haskell formatter
Read 11 Oct 2026 · github.com
On the record
- Browser app
- The project provides a browser-based app, which is redeployed on each new commit to main and may include unreleased changes.github.com · read 11 Oct 2026
- Cabal awareness
- It locates the relevant Cabal file to read default language extensions and dependencies that help determine operator fixities.github.com · read 11 Oct 2026
- Cabal support
- Fourmolu locates the Cabal file for a source file and uses it to obtain default extensions and dependencies.github.com · read 10 Oct 2026
- CI integration
- The README recommends the run-fourmolu GitHub Action for keeping a project formatted.github.com · read 11 Oct 2026
- Configuration
- Settings can be provided in a fourmolu.yaml file or as command-line options.fourmolu.github.io · read 11 Oct 2026
- Current release
- The site lists v0.21.0.0 as the current release.fourmolu.github.io · read 10 Oct 2026
- Editor integration
- Fourmolu can integrate with editors through Haskell Language Server by setting haskell.formattingProvider to fourmolu.github.com · read 11 Oct 2026
- Formatting controls
- It offers configurable options for indentation, line length, imports, records, comments, and other formatting choices.fourmolu.github.io · read 11 Oct 2026
- GitHub Actions
- The README recommends run-fourmolu to ensure a project is formatted with Fourmolu.github.com · read 10 Oct 2026
- Installation
- The project documents installation through GHCup, Cabal, Stack, and dotslash.github.com · read 11 Oct 2026
- Limitation
- CPP support is experimental and works only in simple cases where conditionals surround top-level declarations.github.com · read 11 Oct 2026
- Limitations
- The README describes CPP support as experimental and says it works only in simple cases where CPP conditionals surround top-level declarations.github.com · read 10 Oct 2026
- Line endings
- Fourmolu always outputs LF line endings, so check mode can fail on otherwise formatted files with CRLF endings.github.com · read 11 Oct 2026
- Maintainer attribution
- The README credits Tweag I/O from 2018–2020 and Matt Parsons from 2020 onward.github.com · read 11 Oct 2026
- Project context
- Fourmolu uses GHC's parser and aims for minimal diffs, idempotent formatting, and support for modern Haskell dialects.github.com · read 11 Oct 2026
- Project metadata
- The repository README says the formatter uses GHC's parser and aims for minimal diffs, idempotence, and robustness on large projects.github.com · read 10 Oct 2026
- Purpose
- Fourmolu formats Haskell source code and is a configurable fork of Ormolu.fourmolu.github.io · read 11 Oct 2026
- Selective formatting
- Magic comments can disable formatting for selected top-level definitions, and command-line options can format a chosen line region.github.com · read 11 Oct 2026
The review
Fourmolu is a free, open-source formatter for Haskell projects that need a consistent style without giving up control over individual layout rules. It is best suited to developers maintaining Cabal-based codebases, integrating formatting into editors or CI, and accepting a command-line-centered workflow.
Overview
Fourmolu is a configurable fork of Ormolu built around GHC’s parser. Its stated goals are minimal diffs, idempotent output, robustness on large projects, and support for modern Haskell dialects. In practice, those priorities make it a sensible fit for teams introducing formatting to an existing repository: repeated runs should settle on one result, while smaller changes are easier to review.
Configuration can live in fourmolu.yaml or be supplied as command-line options. Fourmolu also locates the relevant Cabal file and reads language extensions and dependencies, using that project context when determining operator fixities. That Cabal awareness is valuable in repositories where syntax and operators depend on package settings rather than a universal default.
Key features
- Broad style controls: You can set indentation, line length, import grouping, record layout, Haddock comment handling, Unicode output, and operator fixities. This gives a team room to establish its own conventions instead of accepting a single inflexible layout.
- Selective formatting: Magic comments can exempt particular code, and a command-line option can restrict formatting to a specified line region. These controls help when generated, delicate, or intentionally unusual sections should remain untouched.
- Browser preview: An interactive web demo exposes configurable formatting and program options. It is useful for evaluating rules before adding the formatter to a project, although ongoing repository automation still belongs in the installed tooling.
- Editor integration: Haskell Language Server can use Fourmolu by setting haskell.formattingProvider to fourmolu. That places formatting in the editor workflow rather than making developers invoke a separate command for every file.
- CI workflow: The project recommends the run-fourmolu GitHub Action for keeping a repository formatted. This is a straightforward route to enforcing style in pull requests and automation.
- Installation choices: The README recommends GHCup and also documents Cabal, Stack, and dotslash installation. Haskell teams can therefore use the toolchain approach that matches their environment.
Pricing
Fourmolu costs nothing under its open-source plan. There is no paid tier, free trial, seat charge, or usage quota described, so it suits individual developers and teams that want to adopt a formatter without a service subscription. The trade-off is that installation, configuration, and maintenance remain part of the project’s own workflow rather than being handled by a hosted product.
Platforms
Fourmolu is offered for Linux, Windows, and the web. The web option is represented by the browser demo; installation documentation covers command-line use through the Haskell ecosystem. A library API is also available, which is useful when another Haskell tool needs formatting as a component rather than only as a standalone executable.
Who it's for
Choose Fourmolu if you write Haskell and want configurable, repeatable formatting tied to GHC parsing and Cabal metadata. It is particularly well matched to teams using Haskell Language Server, GitHub Actions, or established repositories where minimal diffs matter.
Look elsewhere if your source relies on complex C preprocessor layouts. CPP support is experimental and works only in simple cases where conditionals surround top-level declarations. Projects that must preserve CRLF line endings also need caution: Fourmolu always writes LF, so check mode can reject files that otherwise appear formatted.
Pros and cons
Pros
- Project-aware parsing: GHC parsing plus Cabal-derived extensions, dependencies, and fixities gives formatting useful context in real Haskell packages.
- Configurable enforcement: YAML and command-line settings cover the style decisions teams commonly need, with editor and GitHub Actions integration for day-to-day enforcement.
- Targeted exceptions: Magic comments and line-region formatting prevent an all-or-nothing approach.
- Free and open source: There is no subscription or trial expiration to manage.
Cons
- Restricted CPP handling: Conditional code beyond simple top-level cases may not format reliably.
- LF-only output: Windows-oriented repositories using CRLF can see check-mode failures caused by line-ending conversion.
- Self-managed operation: Teams must install and configure the tool through their Haskell environment rather than relying on a hosted formatter service.
Alternatives
For a different language, swift-format is the free Apache-2.0 option for Swift on iOS and Linux, while Black targets Python across Linux, macOS, self-hosted environments, and Windows. PHP teams should choose Laravel Pint, and Rust projects should use rustfmt.
Zig fmt is the free formatter included with the Zig toolchain. dprint offers a self-managed, MIT-licensed CLI with extension support. Go developers can use gofmt, included with a Go installation. Accessibility Test Framework for Android is a free Android-focused project rather than a direct Haskell formatting substitute. Browse more options in Code Formatting Tools.
Verdict
Fourmolu is the right choice for Haskell developers who want free, configurable formatting that understands GHC and Cabal context and can run in editors and CI. Its main reason to look elsewhere is equally clear: projects with substantial CPP usage or a hard requirement for CRLF-preserving output will encounter constraints that its otherwise strong workflow does not remove.