> ## Documentation Index
> Fetch the complete documentation index at: https://docs.iotools.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Haskell Code Formatter

> Format and pretty-print Haskell source — consistent operator spacing, sorted/deduplicated LANGUAGE pragmas, sorted import blocks, and blank-line collapsing, approximating Fourmolu/Ormolu conventions. Includes basic syntax validation and a long-line report. Runs entirely in your browser.

[Try Haskell Code Formatter in your browser →](https://iotools.cloud/tool/haskell-code-formatter/)



## OpenAPI

````yaml https://api.iotools.cloud/v1/openapi post /v1/tool/haskell-code-formatter
openapi: 3.1.0
info:
  title: iotools.cloud API
  version: 1.0.0
  description: >-
    Run any iotools.cloud tool over HTTP.


    Authenticate with `Authorization: Bearer iot_live_…`.


    **Only `POST /v1/tool/{slug}` costs credits.** Every GET here — the catalog,
    a tool's schema, your balance — is free. A tool call is charged its own
    weight or your plan's per-call minimum, whichever is larger;
    `x-iotools-credit-cost` on each operation is quoted at the free-tier
    minimum, and `GET /v1/tools/list` returns the exact figure for your key.
    `GET /v1/me/credits` reports what you have left, and `GET /v1/me/usage`
    reports what it went on.


    Failures are RFC 9457 problem documents — branch on `code`.
servers:
  - url: https://api.iotools.cloud
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Catalog
    description: Find a tool and read its contract. Free.
  - name: Converters
    description: >-
      Convert between formats, encodings, and units — Base64, CSV and JSON,
      timestamps, and more. Fast, free, and processed right in your browser.
  - name: Formatters
    description: >-
      Format, beautify, minify, and validate code and data — JSON, HTML, CSS,
      SQL, and regex. Clean up messy input in one click, with nothing to upload.
  - name: Generators
    description: >-
      Generate exactly what you need and on demand — passwords, UUIDs, QR codes,
      hashes, random numbers, and more. Secure, instant, and free.
  - name: Calculators
    description: >-
      Crunch the numbers fast — from everyday math to specialized conversions
      and unit work. Free online calculators that run entirely in your browser.
  - name: Editors
    description: >-
      Edit and transform text, code, and images with quick, focused editors that
      run entirely in your browser — nothing to install, and no sign-up needed.
  - name: Utilities
    description: >-
      Everyday developer and web utilities — DNS and IP lookups, redirect and
      certificate checkers, and other quick diagnostics. Free and
      privacy-friendly.
  - name: Account
    description: Your key's allowance, limits and usage history.
paths:
  /v1/tool/haskell-code-formatter:
    post:
      tags:
        - Formatters
      summary: Haskell Code Formatter
      description: >-
        Format and pretty-print Haskell source — consistent operator spacing,
        sorted/deduplicated LANGUAGE pragmas, sorted import blocks, and
        blank-line collapsing, approximating Fourmolu/Ormolu conventions.
        Includes basic syntax validation and a long-line report. Runs entirely
        in your browser.


        [Try Haskell Code Formatter in your browser
        →](https://iotools.cloud/tool/haskell-code-formatter/)
      operationId: run_haskell_code_formatter
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                haskellInput:
                  type: string
                  description: Haskell source code
                indentSize:
                  enum:
                    - '2'
                    - '4'
                  description: Indent size
                maxLineLength:
                  type: number
                  description: Max line length
                  minimum: 60
                  maximum: 200
                sortImports:
                  type: boolean
                  description: Sort import statements within each block
                sortPragmas:
                  type: boolean
                  description: Sort and deduplicate LANGUAGE pragmas at the top
                collapseBlankLines:
                  type: boolean
                  description: Collapse 3+ consecutive blank lines into one
              required: []
            examples:
              module_with_pragmas_imports_records_guards_and_a_where_clause:
                summary: >-
                  Module with pragmas, imports, records, guards and a where
                  clause
                value:
                  haskellInput: >
                    {-# LANGUAGE ScopedTypeVariables #-}

                    {-# LANGUAGE OverloadedStrings #-}

                    {-# LANGUAGE TupleSections #-}

                    module Main where


                    import qualified Data.Map.Strict as Map

                    import Data.List(sort,nub)

                    import Data.Maybe(fromMaybe,catMaybes)

                    import qualified Data.Text as T

                    import System.IO

                    import Control.Monad(forM_,when,unless)


                    -- A simple Person record

                    data
                    Person=Person{personName::String,personAge::Int,personEmail::Maybe
                    String}deriving(Show,Eq)


                    defaultAge::Int

                    defaultAge=18


                    greet::String->String

                    greet name="Hello, "++name++"!"


                    categorize::Int->String

                    categorize age
                      |age<13="child"
                      |age<20="teen"
                      |age<65="adult"
                      |otherwise="senior"

                    processPeople::[Person]->Map.Map String Int

                    processPeople ps=foldr step Map.empty ps
                      where
                        step p acc=Map.insertWith (+) (categorize (personAge p)) 1 acc

                    main::IO ()

                    main=do
                      let people=[Person "Alice" 30 (Just "alice@example.com"),Person "Bob" 12 Nothing,Person "Carol" 67 (Just "carol@example.com")]
                      forM_ people$\p->putStrLn(greet(personName p))
                      let summary=processPeople people
                      mapM_ print(Map.toList summary)
                  indentSize: '2'
                  maxLineLength: '100'
                  sortImports: 'true'
                  sortPragmas: 'true'
                  collapseBlankLines: 'true'
              cons_operator_and_operator_section_spacing_bug_fixes:
                summary: Cons operator and operator section spacing (bug fixes)
                value:
                  haskellInput: |-
                    xs@(x:_) = [1,2,3]
                    rightSection = filter (<5) [1,2,3]
                  indentSize: '2'
                  maxLineLength: '100'
                  sortImports: 'false'
                  sortPragmas: 'false'
                  collapseBlankLines: 'false'
              unbalanced_parenthesis_is_flagged:
                summary: Unbalanced parenthesis is flagged
                value:
                  haskellInput: |
                    f :: Int -> Int
                    f x = (x + 1
                  indentSize: '2'
                  maxLineLength: '100'
                  sortImports: 'false'
                  sortPragmas: 'false'
                  collapseBlankLines: 'false'
      responses:
        '200':
          description: Tool output
          content:
            application/json:
              examples:
                module_with_pragmas_imports_records_guards_and_a_where_clause:
                  summary: >-
                    Module with pragmas, imports, records, guards and a where
                    clause
                  value:
                    tool: haskell-code-formatter
                    tool_version: 1.0.1
                    outputs:
                      formattedOutput: >
                        {-# LANGUAGE OverloadedStrings #-}

                        {-# LANGUAGE ScopedTypeVariables #-}

                        {-# LANGUAGE TupleSections #-}


                        module Main where


                        import Control.Monad (forM_, when, unless)

                        import Data.List (sort, nub)

                        import Data.Maybe (fromMaybe, catMaybes)

                        import System.IO

                        import qualified Data.Map.Strict as Map

                        import qualified Data.Text as T


                        -- A simple Person record

                        data Person = Person {personName :: String, personAge ::
                        Int, personEmail :: Maybe String} deriving (Show, Eq)


                        defaultAge :: Int

                        defaultAge = 18


                        greet :: String -> String

                        greet name = "Hello, " ++ name ++ "!"


                        categorize :: Int -> String

                        categorize age
                          | age < 13 = "child"
                          | age < 20 = "teen"
                          | age < 65 = "adult"
                          | otherwise = "senior"

                        processPeople :: [Person] -> Map.Map String Int

                        processPeople ps = foldr step Map.empty ps
                          where
                            step p acc = Map.insertWith (+) (categorize (personAge p)) 1 acc

                        main :: IO ()

                        main = do
                          let people = [Person "Alice" 30 (Just "alice@example.com"), Person "Bob" 12 Nothing, Person "Carol" 67 (Just "carol@example.com")]
                          forM_ people $ \p -> putStrLn (greet (personName p))
                          let summary = processPeople people
                          mapM_ print (Map.toList summary)
                      validation:
                        - issue: >-
                            Valid Haskell — 2 line(s) exceed 100 chars: line 15
                            (110 chars), line 37 (132 chars)
                    credits_used: 3
                    credits_remaining: null
                cons_operator_and_operator_section_spacing_bug_fixes:
                  summary: Cons operator and operator section spacing (bug fixes)
                  value:
                    tool: haskell-code-formatter
                    tool_version: 1.0.1
                    outputs:
                      formattedOutput: |
                        xs@(x : _) = [1, 2, 3]
                        rightSection = filter (< 5) [1, 2, 3]
                      validation:
                        - issue: Valid Haskell — no syntax errors detected.
                    credits_used: 3
                    credits_remaining: null
                unbalanced_parenthesis_is_flagged:
                  summary: Unbalanced parenthesis is flagged
                  value:
                    tool: haskell-code-formatter
                    tool_version: 1.0.1
                    outputs:
                      formattedOutput: |
                        f :: Int -> Int
                        f x = (x + 1
                      validation:
                        - issue: Missing 1 closing parenthesis(es) ")"
                    credits_used: 3
                    credits_remaining: null
              schema:
                type: object
                required:
                  - tool
                  - tool_version
                  - outputs
                  - credits_used
                  - credits_remaining
                properties:
                  outputs:
                    type: object
                    properties:
                      formattedOutput:
                        type: string
                        description: Formatted Haskell
                      validation:
                        type: array
                        description: Validation
                        items:
                          type: object
                          properties:
                            issue:
                              type: string
                              description: Issue
                        x-iotools-columns:
                          - issue
                  tool:
                    type: string
                    description: The tool's slug, echoing the {slug} in the request path.
                  tool_version:
                    type: string
                    description: Output-contract version for this tool.
                  credits_used:
                    type: integer
                    description: >-
                      Credits this call consumed, after any settlement refund. 0
                      when metering is disabled.
                  credits_remaining:
                    type:
                      - integer
                      - 'null'
                    description: >-
                      Credits left in the current monthly allowance, or null
                      when metering is disabled.
                  request_id:
                    type: string
                    description: Correlation id, also sent as x-request-id.
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '403':
          $ref: '#/components/responses/ToolNotAllowed'
        '404':
          $ref: '#/components/responses/ToolNotFound'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ToolFailed'
        '503':
          $ref: '#/components/responses/ToolDisabled'
      security:
        - bearerAuth: []
components:
  responses:
    ValidationError:
      description: Invalid request.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/validation_error
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Invalid request
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - validation_error
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
              fields:
                type:
                  - object
                  - string
                additionalProperties:
                  type: string
                description: >-
                  What failed: a map of field name → message. Absent when the
                  body itself is malformed; a single string when the failure
                  isn't tied to one field.
          example:
            type: https://iotools.cloud/docs/errors/validation_error
            title: Invalid request
            status: 400
            code: validation_error
            detail: One or more inputs are invalid — see `fields`.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
            fields:
              inputString: Required
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/invalid_api_key
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Invalid API key
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - invalid_api_key
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
          example:
            type: https://iotools.cloud/docs/errors/invalid_api_key
            title: Invalid API key
            status: 401
            code: invalid_api_key
            detail: 'Provide ''Authorization: Bearer <key>''.'
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
    InsufficientCredits:
      description: Monthly credit allowance exhausted.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/insufficient_credits
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Insufficient credits
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - insufficient_credits
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
              credits_used:
                type: integer
                description: Always 0 — a refused call charges nothing.
              credits_remaining:
                type: integer
                description: Credits left in the allowance — fewer than this call costs.
          example:
            type: https://iotools.cloud/docs/errors/insufficient_credits
            title: Insufficient credits
            status: 402
            code: insufficient_credits
            detail: This call costs 1 credit and 0 remain in this month's allowance.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
            credits_used: 0
            credits_remaining: 0
    ToolNotAllowed:
      description: Tool exists but has no API surface.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/tool_not_allowed
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Tool not available over the API
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - tool_not_allowed
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
          example:
            type: https://iotools.cloud/docs/errors/tool_not_allowed
            title: Tool not available over the API
            status: 403
            code: tool_not_allowed
            detail: >-
              "Background Remover" is available on iotools.cloud but has no API
              endpoint.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
    ToolNotFound:
      description: No such tool.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/tool_not_found
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Tool not found
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - tool_not_found
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
          example:
            type: https://iotools.cloud/docs/errors/tool_not_found
            title: Tool not found
            status: 404
            code: tool_not_found
            detail: No tool with that slug. See GET /v1/tools/list.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
    PayloadTooLarge:
      description: Body too large.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/payload_too_large
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Payload too large
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - payload_too_large
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
          example:
            type: https://iotools.cloud/docs/errors/payload_too_large
            title: Payload too large
            status: 413
            code: payload_too_large
            detail: Request body exceeds this tool's size limit.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
    RateLimited:
      description: Per-minute rate limit exceeded.
      headers:
        Retry-After:
          description: Seconds to wait before retrying (RFC 9110 delta-seconds).
          schema:
            type: integer
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/rate_limited
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Rate limit exceeded
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - rate_limited
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
              retry_after:
                type: integer
                description: >-
                  Seconds until the window resets — the same value as the
                  `Retry-After` header.
          example:
            type: https://iotools.cloud/docs/errors/rate_limited
            title: Rate limit exceeded
            status: 429
            code: rate_limited
            detail: Too many requests. Retry in 30s.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
            retry_after: 30
    ToolFailed:
      description: Tool failed to run.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/processing_error
                  - https://iotools.cloud/docs/errors/internal_error
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Tool failed to run
                  - Internal error
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - processing_error
                  - internal_error
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
              credits_used:
                type: integer
                description: >-
                  Always 0 on `processing_error` — a failed run is refunded,
                  floor included.
              credits_remaining:
                type: integer
                description: >-
                  Credits left after the refund. Absent when metering is
                  disabled.
          example:
            type: https://iotools.cloud/docs/errors/processing_error
            title: Tool failed to run
            status: 500
            code: processing_error
            detail: The tool failed to run. Please try again.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
            credits_used: 0
    ToolDisabled:
      description: Tool temporarily disabled.
      content:
        application/problem+json:
          schema:
            type: object
            description: >-
              RFC 9457 problem document, served as application/problem+json.
              Branch on `code`; `title` is human prose and may be reworded
              without notice. Some failures add extension members — `fields` on
              validation errors, `retry_after` on 429s,
              `credits_used`/`credits_remaining` on billing-adjacent failures —
              documented on the responses that carry them.
            required:
              - type
              - title
              - status
              - code
            properties:
              type:
                type: string
                format: uri
                description: Stable documentation URI for this failure.
                examples:
                  - https://iotools.cloud/docs/errors/tool_disabled
                  - https://iotools.cloud/docs/errors/api_unconfigured
              title:
                type: string
                description: Short human-readable summary of the failure.
                examples:
                  - Tool temporarily disabled
                  - API not configured
              status:
                type: integer
                description: HTTP status code, matching the response's own status.
              code:
                type: string
                description: >-
                  Stable machine-readable error code — branch on this, not
                  `title`.
                enum:
                  - tool_disabled
                  - api_unconfigured
              detail:
                type: string
                description: Human explanation of this occurrence.
              request_id:
                type: string
                description: Correlation id, also sent as x-request-id.
          example:
            type: https://iotools.cloud/docs/errors/tool_disabled
            title: Tool temporarily disabled
            status: 503
            code: tool_disabled
            detail: This tool is temporarily unavailable. Try again shortly.
            request_id: e4042b29-8f1e-4c7a-9b52-6f0d1a3c7e11
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: iot_live_…

````