Build Status


A simple Haskell code prettifier. The goal is not to format all of the code in a file, since I find those kind of tools often "get in the way". However, manually cleaning up import statements etc. gets tedious very quickly.

This tool tries to help where necessary without getting in the way.


You can install it using stack install stylish-haskell or cabal install stylish-haskell.

You can also install it using your package manager: Debian 9 or later: apt-get install stylish-haskell Ubuntu 16.10 or later: apt-get install stylish-haskell * Arch Linux: pacman -S stylish-haskell


  • Aligns and sorts import statements
  • Groups and wraps {-# LANGUAGE #-} pragmas, can remove (some) redundant pragmas
  • Removes trailing whitespace
  • Aligns branches in case and fields in records
  • Converts line endings (customizable)
  • Replaces tabs by four spaces (turned off by default)
  • Replaces some ASCII sequences by their Unicode equivalents (turned off by default)

Feature requests are welcome! Use the issue tracker for that.



{-# LANGUAGE ViewPatterns, TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving,
    ScopedTypeVariables #-}

module Bad where

import Control.Applicative ((<$>))
import System.Directory (doesFileExist)

import qualified Data.Map as M
import      Data.Map    ((!), keys, Map)

data Point = Point
    { pointX, pointY :: Double
    , pointName :: String
    } deriving (Show)


{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TemplateHaskell            #-}

module Bad where

import           Control.Applicative ((<$>))
import           System.Directory    (doesFileExist)

import           Data.Map            (Map, keys, (!))
import qualified Data.Map            as M

data Point = Point
    { pointX, pointY :: Double
    , pointName      :: String
    } deriving (Show)


The tool is customizable to some extent. It tries to find a config file in the following order:

  1. A file passed to the tool using the -c/--config argument
  2. .stylish-haskell.yaml in the current directory (useful for per-directory settings)
  3. .stylish-haskell.yaml in the nearest ancestor directory (useful for per-project settings)
  4. stylish-haskell/config.yaml in the platform’s configuration directory (on Windows, it is %APPDATA%, elsewhere it defaults to ~/.config and can be overridden by the XDG_CONFIG_HOME environment variable; useful for user-wide settings)
  5. .stylish-haskell.yaml in your home directory (useful for user-wide settings)
  6. The default settings.

Use stylish-haskell --defaults > .stylish-haskell.yaml to dump a well-documented default configuration to a file, this way you can get started quickly.

VIM integration

Since it works as a filter it is pretty easy to integrate this with VIM.

You can call


and add a keybinding for it.

Or you can define formatprg

:set formatprg=stylish-haskell

and then use gq.

There is also the vim-stylish-haskell plugin, which runs stylish-haskell automatically when you save a Haskell file.

Emacs integration

haskell-mode for Emacs supports stylish-haskell. For configuration, see the “Using external formatters” section of the haskell-mode manual.

Atom integration

ide-haskell for Atom supports stylish-haskell.

atom-beautify for Atom supports Haskell using stylish-haskell.


Written and maintained by Jasper Van der Jeugt.


  • Chris Done
  • Hiromi Ishii
  • Leonid Onokhov
  • Michael Snoyman
  • Mikhail Glushenkov



- (2018-01-03)
* Bump lower bound of `directory` to `1.2.3` for `getXdgDirectory`

- (2017-12-29)
* Fix missing Extra-source-file in cabal file

- (2017-12-26)
* Embed the default configuration
* Add platform-specific configuration paths (by Jan Tojnar)
* Bump `haskell-src-exts` to 0.20
* Avoid unpaired parenthesis when import doesn't specify any items (by
Matthew Kennerly)
* Remove shebang lines at the beginning of file (by Vaibhav Sagar)

- (2017-06-19)
* Add `pad_module_names` option (by Yuriy Syrovetskiy)
* Add `space_surround` option to import styling (by Linus Arver)
* Bump `optparse-applicative` to 0.14

* Remove `MagicHash` from whitelisted language extensions, since it was
causing parsing errors (by Artyom Kazak)
* Don't leave a `#-}` hanging on the next line when `language_pragmas`
is set to `compact` and the `#-}` doesn't fit into character limit
(by Artyom Kazak)
* Deduplicate import specs (i.e. `import Foo (a, a, b)` becomes
`import Foo (a, b)`) (by Artyom Kazak)
* Take package imports into account when prettifying imports
(by Artyom Kazak)
* Bump `aeson` to 1.2
* Bump `syb` to 0.7
* Bump `HUnit` to 1.6

* Keep `safe` and `{-# SOURCE #-}` import annotations (by Moritz Drexl)

* If there's parse errors, show these and exit with code 1
* Bump `aeson` to 1.1
* Bump `directory` to 1.3
* Bump `haskell-src-exts` to 1.19

* Fix issue with unit records (by Mizunashi Mana)
* Bump `HUnit` to 1.5

* Remove `XmlSyntax` from whitelisted language extensions, since it was
causing parsing errors

* Bump `optparse-applicative` to
* Export Import options & add a default
* Add `list_padding: module_name` option (by Oleg Grenrus)
* Bump `aeson` to 1.0 (by Oleg Grenrus)
* Special setting for empty import lists (by Oleg Grenrus)

* Bump `haskell-src-exts` to 1.18

* Fix line patching issue in Editor

* Add a `simple_align` step
* Move `records` step into `simple_align`
* Use a set of default language extensions for parsing (by Langston Barrett)
* Add a newline format option (by Svyatolslav Gryaznov)
* Add more symbols from UnicodeSyntax (by Langston Barrett)
* Add a `--version` option (by Ondra Pelech)

* Remove shebang from input before attempting to extract pragmas
* Set stdin and stdout encoding to UTF-8 by default

* Fail if the default configuration file is not found.

* Bump `aeson` to 0.11

* Fix error that caused haddock to bail on this package

* Add new options for import list alignment (by Ondřej Janošík)

* Bump `stylish-haskell` to 1.17.0

* Bump `HUnit` to 1.13

* Bump `aeson` to 0.10
* Bump `syb` to 0.6

* Bump `aeson` to 0.9

* Bump `syb` to 0.5
* Slight refactoring in align code

* Fix issue with shebang code

* Add support for shebang at start of file

* Bump `filepath` dependency to 1.5

* Fix -Wall compilation with GHC 7.10

* Bump `haskell-src-exts` dependency to 1.16

* Bump `mtl` dependency to 2.2

* Bump `aeson` dependency to 0.8

* Bump `haskell-src-exts` dependency to 1.15
* Fix test which was not run before

- ``
* Add `compact_line` setting for Language Pragma styling
comments powered byDisqus