Rana - Free Online Web Utilities & Software Engineering
Advertisement Responsive AdSense Leaderboard (728x90)
Client-Side Haskell & Monadic Code Beautifier

Online Haskell Code Formatter & Beautifier

Clean, structure, and auto-indent Haskell modules, monadic do-blocks, where/let clauses, and algebraic data types instantly. Enforce clean 2-space or 4-space layout alignment with zero server transmission.

0 Max Nesting
0 Scope Clauses
0 Total Lines
0 Characters
Indent Size:
Load Sample: |
Formatter Status & Scope Audit
Ready: Code structured and properly indented.
Open in Haskell Validator
Advertisement
In-Feed / Mid-Content Responsive Display Unit

Understanding the Haskell Layout Rule & Indentation

Haskell uses the famous off-side rule (syntactic layout), meaning that whitespace and indentation define code blocks without needing curly braces or semicolons. Keywords like where, let, do, case...of, and class establish an indentation column for all subsequent statements. Misaligned indentation is one of the most common compilation blockers in GHC, making automated layout indentation essential.

The Standard 2-Space Rule

Modern formatters like Ormolu and Fourmolu standardize on 2 spaces per indentation level. Hard tabs (\t) are strictly forbidden in GHC by default because their visual width varies across editors.

Monadic do Notation

Statements inside a do block must align vertically to the same column. Any statement indented further is treated as a continuation of the previous expression.

Haskell Style Guidelines: Standard Conventions vs. Messy Layouts

Construct Unformatted / Misaligned Beautified Haskell Standard Formatting Rule
Monadic Do Block main = do
putStrLn "Hello"
name <- getLine
putStrLn name
main = do
  putStrLn "Hello"
  name <- getLine
  putStrLn name
2-space indent for all statements inside the do context.
Data Declaration data Tree a = Leaf a | Node (Tree a) (Tree a) data Tree a
  = Leaf a
  | Node (Tree a) (Tree a)
Aligning constructors with leading pipes enhances readability.
Where Clause calc x = x * factor
where factor = 42
calc x = x * factor
  where
    factor = 42
Indenting where prevents lexical collisions with top-level decls.

Frequently Asked Questions

What indentation style does this Haskell formatter follow?

By default, it follows modern Haskell community conventions (similar to Ormolu and Fourmolu), utilizing 2 spaces or 4 spaces per nesting level without hard tabs.

How does it handle Haskell's off-side layout rule?

The engine identifies layout-triggering keywords such as 'do', 'where', 'let', 'of', and 'mdo', calculating consistent column indentations so that lexical scope is clearly preserved.

Is my proprietary Haskell source code sent to a remote server?

No. All formatting logic runs entirely in your browser using JavaScript lexical parsing. Zero code or telemetry is transmitted across the network.