不喜欢广告? 无广告 今天

Haskell 代码格式化程序(Fourmolu / Ormolu 风格)

开发人员文本
广告 移除?

或者
Lines longer than this are flagged in the report (Ormolu / Fourmolu default is 100).
广告 移除?

指导

Haskell Code Formatter (Fourmolu / Ormolu Style)

Haskell 代码格式化程序(Fourmolu / Ormolu 风格)

Paste raw Haskell source and get back code formatted to a deterministic, Fourmolu / Ormolu-inspired style — with consistent operator spacing, sorted LANGUAGE pragmas, grouped imports, and tabs normalized to spaces. Everything runs locally in your browser, so your source code never leaves your machine.

如何使用

  1. Upload a .hs file or paste your Haskell source into the input box (use the “Try an example” link for a quick sample).
  2. Pick your indent size — 2 spaces (Fourmolu default) or 4 spaces (Ormolu default).
  3. Set the max line length used to flag overly long lines in the validation summary (defaults to 100).
  4. 切换 排序导入, Sort & deduplicate LANGUAGE pragmas,并且 合并空行 to match your project’s house style.
  5. The formatted output appears automatically with syntax highlighting; use Copy or Download to grab the result.

特征

  • Deterministic spacing — adds canonical spaces around =, ::, ->, <-, =>, $, ++, comparison operators, and Applicative / Monad combinators like <$>, <*>, >>=.
  • Pragma normalization — pulls every {-# LANGUAGE ... #-} pragma to the top of the file, splits combined pragmas into one extension per line, sorts them alphabetically, and removes duplicates.
  • 导入排序 — sorts consecutive import statements alphabetically by module name while preserving the unqualified / qualified grouping convention.
  • Layout-safe — preserves the user’s leading indentation (Haskell’s layout rule is significant) while converting tabs to spaces using the chosen indent width.
  • Comment-safe tokenizer — correctly handles line comments (--), nested block comments ({- ... -}), pragmas, strings with escapes, and character literals so operator characters inside them are never mangled.
  • Bracket + block validation — flags unbalanced parentheses, brackets, braces, and unterminated block comments with line numbers.
  • Long-line report — highlights any line that exceeds your configured maximum width so you can refactor before review.
  • 100% 客户端 — your code is processed entirely in the browser; nothing is uploaded, logged, or stored.

常问问题

  1. What is the difference between Ormolu and Fourmolu?

    Ormolu is a strict, opinionated Haskell formatter with effectively no configuration — every project formatted by Ormolu looks the same. Fourmolu is a fork of Ormolu that exposes a handful of style knobs (indentation size, comma placement, leading-vs-trailing commas, record-brace spacing) for teams that want a consistent style that is not identical to upstream Ormolu. Both share the same parser and AST-driven approach, so they produce reliably valid Haskell.

  2. Why is Haskell formatting hard for general-purpose AI?

    Haskell uses the off-side rule — indentation is semantically significant and determines where blocks like let, where, do, and case ... of begin and end. A formatter must understand the parse tree, not just the token stream, to re-indent safely without changing program meaning. General-purpose language models reason about code as text and routinely produce indentation that compiles differently from the input, especially for nested where-clauses and multi-line lambdas.

  3. What is a LANGUAGE pragma?

    A LANGUAGE pragma is a directive of the form {-# LANGUAGE ExtensionName #-} placed at the top of a Haskell source file to enable a GHC language extension for that module — for example OverloadedStrings, ScopedTypeVariables, or TypeApplications. Pragmas can be combined ({-# LANGUAGE A, B, C #-}) but most style guides recommend one extension per line and alphabetical sorting for easy diffs.

  4. Why are qualified imports usually grouped separately?

    Convention groups qualified imports (import qualified Data.Map as M) after plain imports (import Data.List) so a reader can scan unqualified names first and see at a glance which modules are accessed through aliases. This is the layout produced by stylish-haskell, Ormolu, and Fourmolu by default, and it keeps merge conflicts localized when a project adds or removes qualified aliases.

想要享受无广告的体验吗? 立即无广告

安装我们的扩展

将 IO 工具添加到您最喜欢的浏览器,以便即时访问和更快地搜索

添加 Chrome 扩展程序 添加 边缘延伸 添加 Firefox 扩展 添加 Opera 扩展

记分板已到达!

记分板 是一种有趣的跟踪您游戏的方式,所有数据都存储在您的浏览器中。更多功能即将推出!

广告 移除?
广告 移除?
广告 移除?

新闻角 包含技术亮点

参与其中

帮助我们继续提供有价值的免费工具

给我买杯咖啡
广告 移除?