Anúncios incomodam? Ir Sem anúncios Hoje

Formatação de Código Haskell (Estilo Fourmolu / Ormolu)

DesenvolvedorTexto
ANUNCIADO Remover?

Ou
Lines longer than this are flagged in the report (Ormolu / Fourmolu default is 100).
ANUNCIADO Remover?

Guia

Haskell Code Formatter (Fourmolu / Ormolu Style)

Formatação de Código Haskell (Estilo 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.

Como usar

  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. Alternar Ordenar importações, Sort & deduplicate LANGUAGE pragmase, e Collapse blank lines to match your project’s house style.
  5. The formatted output appears automatically with syntax highlighting; use Copy or Download to grab the result.

Características

  • 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.
  • Ordenação de imports — 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% do lado do cliente — your code is processed entirely in the browser; nothing is uploaded, logged, or stored.

Perguntas frequentes

  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.

Quer eliminar anúncios? Fique sem anúncios hoje mesmo

Instale nossas extensões

Adicione ferramentas de IO ao seu navegador favorito para acesso instantâneo e pesquisa mais rápida

Ao Extensão do Chrome Ao Extensão de Borda Ao Extensão Firefox Ao Extensão Opera

O placar chegou!

Placar é uma forma divertida de acompanhar seus jogos, todos os dados são armazenados em seu navegador. Mais recursos serão lançados em breve!

ANUNCIADO Remover?
ANUNCIADO Remover?
ANUNCIADO Remover?

Notícias com destaques técnicos

Envolver-se

Ajude-nos a continuar fornecendo ferramentas gratuitas valiosas

Compre-me um café
ANUNCIADO Remover?