### Basic Formatting Example Source: https://fourmolu.github.io/ Demonstrates basic code formatting with Fourmolu. Ensure Fourmolu is installed and accessible in your PATH. ```shell fourmolu --check src/MyModule.hs ``` -------------------------------- ### Inline let-style Example Source: https://fourmolu.github.io/config/let-style Demonstrates the `inline` style for `let` blocks where bindings appear on the same line as the `let`/`in` keywords. ```Haskell testUser = let name = "Alice" age = 30 in User name age ``` -------------------------------- ### Default Indentation (4 spaces) Source: https://fourmolu.github.io/config/indentation Example demonstrating default code indentation with 4 spaces. ```Haskell login :: IO () login = do name <- getLine if name == "admin" then putStrLn "Logged in!" else do putStrLn "Incorrect username" login ``` -------------------------------- ### Type Annotation Example Source: https://fourmolu.github.io/ Demonstrates a type annotation involving MonadIO and a function type. ```Haskell ([], (EpaComments []))) (HsAppTy (NoExtField) (L (EpAnn (EpaSpan { :25:6-14 }) (AnnListItem []) (EpaComments [])) (HsTyVar (NoEpTok) (NotPromoted) (L (EpAnn (EpaSpan { :25:6-12 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: MonadIO})))) (L (EpAnn (EpaSpan { :25:14 }) (AnnListItem []) (EpaComments [])) (HsTyVar (NoEpTok) (NotPromoted) (L (EpAnn (EpaSpan { :25:14 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: m}))))))) (L (EpAnn (EpaSpan { :26:5-15 }) (AnnListItem []) (EpaComments [])) (HsFunTy (NoExtField) (HsUnrestrictedArrow (EpUniTok (EpaSpan { :26:9-10 }) (NormalSyntax))) (L (EpAnn (EpaSpan { :26:5-7 }) (AnnListItem []) (EpaComments [])) (HsTyVar (NoEpTok) (NotPromoted) (L (EpAnn (EpaSpan { :26:5-7 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: Int})))) (L (EpAnn (EpaSpan { :26:12-15 }) (AnnListItem []) (EpaComments [])) (HsAppTy (NoExtField) (L (EpAnn (EpaSpan { :26:12 }) (AnnListItem []) (EpaComments [])) (HsTyVar (NoEpTok) (NotPromoted) (L (EpAnn (EpaSpan { :26:12 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: m})))) (L (EpAnn (EpaSpan { :26:14-15 }) (AnnListItem []) (EpaComments [])) (HsTupleTy (AnnParens (EpTok (EpaSpan { :26:14 })) (EpTok (EpaSpan { :26:15 }))) (HsBoxedOrConstraintTuple) [])))))))))))) ``` -------------------------------- ### Ormolu Indentation (2 spaces) Source: https://fourmolu.github.io/config/indentation Example demonstrating code indentation with 2 spaces, similar to Ormolu's style. ```Haskell login :: IO () login = do name <- getLine if name == "admin" then putStrLn "Logged in!" else do putStrLn "Incorrect username" login ``` -------------------------------- ### Newline let-style Example Source: https://fourmolu.github.io/config/let-style Illustrates the `newline` style for `let` blocks, where bindings are placed on the line following the `let`/`in` keywords. ```Haskell testUser = let name = "Alice" age = 30 in User name age ``` -------------------------------- ### Leading Comma Style Example Source: https://fourmolu.github.io/config/comma-style Demonstrates the default `leading` comma style for multi-line data declarations and lists. ```Haskell data User = User { userName :: String, userAge :: Int, userActive :: Bool } forbiddenPasswords :: [String] forbiddenPasswords = [ "password", "hunter2", "123456" ] ``` -------------------------------- ### Using Fourmolu Programmatically (Haskell) Source: https://fourmolu.github.io/ Provides an example of how to use Fourmolu's formatting capabilities within a Haskell program. Requires importing the Fourmolu module. ```haskell import Fourmolu main :: IO () main = do let code = "import Data.List\n\nfoo = [1,2,3]" formattedCode <- format code putStrLn formattedCode ``` -------------------------------- ### Record Brace Space: With Spacing Source: https://fourmolu.github.io/config/record-brace-space This example shows the `record-brace-space` option set to `true`, where a space is present before the opening brace of a record. ```haskell getUsername :: User -> String getUsername User {..} = username ``` -------------------------------- ### Code with Parentheses Source: https://fourmolu.github.io/config/single-constraint-parens Example of a function signature with parentheses around a single constraint. ```Haskell logAction :: (MonadLogger m) => String -> m () logAction msg = logDebugN $ "Action: " <> msg ``` -------------------------------- ### Fixed Point Example for Multiline Constructs in Do Blocks Source: https://fourmolu.github.io/changelog This snippet demonstrates a fixed point for formatting multiline constructs within do blocks, illustrating potential odd indentations. ```haskell foo = do do (+1) 1 ``` -------------------------------- ### Single-line Haddock Comments Source: https://fourmolu.github.io/config/haddock-style Example of single-line Haddock comments using -- | syntax. ```haskell -- | Get the user with the given username getUser :: String -> IO (Maybe User) -- | Same as 'getUsername', except throw -- an error if the user doesn't exist. loadUser :: String -> IO User ``` -------------------------------- ### Multi-line Haddock Comments Source: https://fourmolu.github.io/config/haddock-style Example of multi-line Haddock comments using {-# ... #-} syntax. ```haskell -- | Get the user with the given username getUser :: String -> IO (Maybe User) {- | Same as 'getUsername', except throw an error if the user doesn't exist. -} loadUser :: String -> IO User ``` -------------------------------- ### Code without Trailing Section Operators Source: https://fourmolu.github.io/config/trailing-section-operators Example showing code formatting when trailing section operators are disabled. Each application of the operator starts on a new indented line. ```Haskell foo :: IO () foo = bar $ baz $ bat $ quiz x ``` -------------------------------- ### Code With Unicode Syntax Source: https://fourmolu.github.io/config/unicode Example of Haskell code with Unicode syntax enabled, demonstrating the use of Unicode characters for operators and type annotations. ```haskell {-# LANGUAGE UnicodeSyntax #} loadUser ∷ ∀ m. (MonadIO m) ⇒ String → m User loadUser username = do mUser ← getUser username maybe (error "Unknown user") pure mUser ``` -------------------------------- ### Multi-line Compact Haddock Comments Source: https://fourmolu.github.io/config/haddock-style Example of multi-line compact Haddock comments using {-# ... #-} syntax on a single line. ```haskell -- | Get the user with the given username getUser :: String -> IO (Maybe User) {-| Same as 'getUsername', except throw an error if the user doesn't exist. -} loadUser :: String -> IO User ``` -------------------------------- ### Function signature with sorted constraints Source: https://fourmolu.github.io/config/sort-constraints Example of a function signature where constraints are sorted alphabetically. This occurs when `sort-constraints` is set to `true`. ```haskell f :: (Eq a, Show a) => a ``` -------------------------------- ### Record Brace Space: Without Spacing Source: https://fourmolu.github.io/config/record-brace-space This example shows the `record-brace-space` option set to `false` (default), where no space is present before the opening brace of a record. ```haskell getUsername :: User -> String getUsername User{..} = username ``` -------------------------------- ### Code Without Unicode Syntax Source: https://fourmolu.github.io/config/unicode Example of Haskell code without enabling Unicode syntax. This is the default behavior. ```haskell {-# LANGUAGE UnicodeSyntax #} loadUser :: forall m. (MonadIO m) => String -> m User loadUser username = do mUser <- getUser username maybe (error "Unknown user") pure mUser ``` -------------------------------- ### Custom Import Grouping Rule Example Source: https://fourmolu.github.io/config/import-grouping Defines a custom import grouping configuration with multiple named groups and specific rules based on glob patterns, scope, and qualification. ```yaml import-grouping: - name: "Text modules" rules: - glob: Data.Text - name: "The rest" rules: - priority: 100 - name: "My internals and monads unqualified" rules: - scope: local qualified: no - glob: Control.Monad qualified: no - name: "My internals and monads qualified" rules: - scope: local qualified: yes - glob: Control.Monad qualified: yes - name: "Specific monads" rules: - glob: Control.Monad.** ``` -------------------------------- ### Enable OverloadedRecordDot and OverloadedRecordUpdate Source: https://fourmolu.github.io/changelog These GHC language extensions are supported by Ormolu starting from version 9.2. They are disabled by default. ```haskell OverloadedRecordDot OverloadedRecordUpdate ``` -------------------------------- ### Haddock Single-line Module Docstring Source: https://fourmolu.github.io/config/haddock-style-module Example of a Haddock module docstring using line comment syntax. This style is suitable for concise module descriptions. ```haskell -- | -- Module: MyModule -- Author: Joe Haskell -- -- The primary API for my library. module MyModule where ``` -------------------------------- ### Code without Parentheses Source: https://fourmolu.github.io/config/single-constraint-parens Example of a function signature without parentheses around a single constraint. ```Haskell logAction :: MonadLogger m => String -> m () logAction msg = logDebugN $ "Action: " <> msg ``` -------------------------------- ### Aligned Record Style Source: https://fourmolu.github.io/config/record-style Demonstrates the 'aligned' style for record declarations and default values. Braces are aligned with the start of the record definition. ```Haskell data User = User { userName :: String, userAge :: Int, userActive :: Bool } defaultUser = User { userName = "", userAge = -1, userActive = false } ``` -------------------------------- ### Haddock Multi-line Compact Module Docstring Source: https://fourmolu.github.io/config/haddock-style-module Example of a compact multi-line Haddock module docstring using block comment syntax. This style minimizes whitespace within the comment block. ```haskell {-| Module: MyModule Author: Joe Haskell The primary API for my library. -} module MyModule where ``` -------------------------------- ### Deriving with Parentheses Source: https://fourmolu.github.io/config/single-deriving-parens Example of a deriving clause formatted with parentheses. Use this when you want to enforce the presence of parentheses around single deriving clauses. ```Haskell data Foo = Foo deriving stock (Show) ``` -------------------------------- ### Configure Indentation in YAML Source: https://fourmolu.github.io/config Specify the `indentation` option within the `fourmolu.yaml` file to set the number of spaces per indentation step. This is an example of how to set a specific configuration option in the YAML file. ```yaml indentation: 2 ``` -------------------------------- ### Example of Sorted Deriving Clauses Source: https://fourmolu.github.io/config/sort-deriving-clauses This snippet demonstrates a `newtype` declaration with alphabetically sorted deriving clauses. This is the result when `sort-deriving-clauses` is `true`. ```haskell newtype A = A Int deriving (ToJSON) deriving stock (Show, Eq, Ord, Generic) deriving newtype (Num) ``` -------------------------------- ### Haddock Multi-line Module Docstring Source: https://fourmolu.github.io/config/haddock-style-module Example of a multi-line Haddock module docstring using block comment syntax. This style is often used for more detailed module descriptions. ```haskell {- | Module: MyModule Author: Joe Haskell The primary API for my library. -} module MyModule where ``` -------------------------------- ### Code with Trailing Section Operators Source: https://fourmolu.github.io/config/trailing-section-operators Example demonstrating the use of trailing section operators, where the expression continues indented below the operator. ```Haskell foo :: IO () foo = bar $ baz $ bat $ quiz x ``` -------------------------------- ### Example of Unsorted Deriving Clauses Source: https://fourmolu.github.io/config/sort-deriving-clauses This snippet shows a `newtype` declaration with deriving clauses in their original, unsorted order. Use this when `sort-deriving-clauses` is `false`. ```haskell newtype A = A Int deriving newtype (Num) deriving (ToJSON) deriving stock (Show, Eq, Ord, Generic) ``` -------------------------------- ### Function signature without sorted constraints Source: https://fourmolu.github.io/config/sort-constraints Example of a function signature where constraints are not sorted alphabetically. This is the default behavior when `sort-constraints` is `false`. ```haskell f :: (Show a, Eq a) => a ``` -------------------------------- ### Deriving without Parentheses Source: https://fourmolu.github.io/config/single-deriving-parens Example of a deriving clause formatted without parentheses. Use this when you want to enforce the absence of parentheses around single deriving clauses. ```Haskell data Foo = Foo deriving stock Show ``` -------------------------------- ### Haskell Import Statement with Explicit Imports Source: https://fourmolu.github.io/ Demonstrates a Haskell import declaration for the 'Person' module, explicitly importing 'Person', 'name', and 'loadPerson'. It also shows an example of importing a module with a qualified name. ```haskell import Person (Person(..), name, loadPerson) ``` -------------------------------- ### Derived Classes With Sorting Source: https://fourmolu.github.io/config/sort-derived-classes Example of a deriving clause where classes are sorted alphabetically. This behavior is enabled when `sort-derived-classes` is true. Note that comments within deriving clauses may be misplaced when this option is used. ```haskell data A deriving stock (Eq, Generic, Ord, Show) ``` -------------------------------- ### Formatting with Configuration Source: https://fourmolu.github.io/ Shows how to apply formatting using a specific configuration file. The config file allows for custom formatting rules. ```shell fourmolu --config fourmolu.yaml src/MyModule.hs ``` -------------------------------- ### Run Query with Parameters Source: https://fourmolu.github.io/ This snippet demonstrates how to execute a query with specific parameters. It shows the invocation of a `runQuery` function with a `queryText` and a list of arguments, likely for dynamic query generation or data filtering. ```haskell runQuery queryText [arg1, arg2] ``` -------------------------------- ### Formatting Multiple Files Source: https://fourmolu.github.io/ Illustrates formatting multiple Haskell files at once. This is useful for batch processing your codebase. ```shell fourmolu src/ ``` -------------------------------- ### Generate Default Configuration File Source: https://fourmolu.github.io/config Use this command to create a `fourmolu.yaml` file pre-filled with default configuration values. This file can then be edited to customize FourMolu's behavior. ```bash $ fourmolu --print-defaults > fourmolu.yaml ``` -------------------------------- ### Ignoring Specific Files Source: https://fourmolu.github.io/ Demonstrates how to exclude certain files or directories from the formatting process using a .fourmolu-ignore file. ```shell fourmolu --ignore-config .fourmolu-ignore src/ ``` -------------------------------- ### Minimal Imports with Internal Modules Grouped Source: https://fourmolu.github.io/config/import-grouping A concise import style focusing on essential modules, with internal modules grouped separately. ```haskell import Data.Text (Text) import qualified Data.Text import Data.Maybe (maybe) import Data.Text.IO (hGetLine) import qualified System.IO as SIO import Text.Printf (printf) import Control.Monad (Monad (..)) import SomeInternal.Module1 (anotherDefinition, someDefinition) import SomeInternal.Module1.SubModuleA import qualified SomeInternal.Module2 as Mod2 import qualified Control.Monad.Error as Error import Control.Monad.State.Lazy (MonadState (..)) ``` -------------------------------- ### Standard Import Grouping Source: https://fourmolu.github.io/config/import-grouping Demonstrates a common import grouping strategy with standard library modules first, followed by internal and qualified imports. ```haskell import Control.Monad (Monad (..)) import qualified Control.Monad.Error as Error import Control.Monad.State.Lazy (MonadState (..)) import Data.Maybe (maybe) import Data.Text (Text) import qualified Data.Text import Data.Text.IO (hGetLine) import SomeInternal.Module1 (anotherDefinition, someDefinition) import SomeInternal.Module1.SubModuleA import qualified SomeInternal.Module2 as Mod2 import qualified System.IO as SIO import Text.Printf (printf) ``` -------------------------------- ### Derived Classes Without Sorting Source: https://fourmolu.github.io/config/sort-derived-classes Example of a deriving clause where classes are not sorted alphabetically. This is the default behavior when `sort-derived-classes` is false. ```haskell data A deriving stock (Show, Eq, Ord, Generic) ``` -------------------------------- ### Use OverloadedRecordDot for Getter Syntax Source: https://fourmolu.github.io/changelog Consider using the OverloadedRecordDot language extension as a replacement for the record-dot-preprocessor. ```haskell OverloadedRecordDot ``` -------------------------------- ### Provide Fixity Overrides via Command Line Source: https://fourmolu.github.io/changelog Use the -f or --fixity command-line option to provide user-defined fixity declarations for Ormolu. Each declaration should be on a new line. ```bash -f / --fixity ``` -------------------------------- ### Code Formatting with 40 Character Limit Source: https://fourmolu.github.io/config/column-limit This snippet demonstrates code formatting when a 40-character column limit is enforced. Lines are broken to stay within this limit. ```haskell rootUsers :: [String] rootUsers = ["root"] adminUsers :: [String] adminUsers = [ "hunter2" , "elon.musk" , "simon.peyton.jones" ] regularUsers :: [String] regularUsers = [ "alice" , "bob" , "charlie" , "david" , "eve" , "felicia" , "greg" , "hailey" , "isaac" ] ``` -------------------------------- ### Leading Import/Export Style Source: https://fourmolu.github.io/config/import-export-style Illustrates the 'leading' style for import and export lists. This style groups items on the same line when possible, with subsequent items on new lines. ```Haskell module MyModule ( User (..) , createUser , deleteUser ) where import MyModule.Internal ( User , createUser , deleteUser ) ``` -------------------------------- ### Format Backpack Signature Files with Ormolu Source: https://fourmolu.github.io/changelog Ormolu supports formatting Backpack signature files (.hsig). The source type can be overridden with the -t or --source-type command line option. ```bash -t / --source-type ``` -------------------------------- ### Default Code Formatting (No Limit) Source: https://fourmolu.github.io/config/column-limit This snippet shows the default formatting when no column limit is applied. Lines are kept as short as possible. ```haskell rootUsers :: [String] rootUsers = ["root"] adminUsers :: [String] adminUsers = ["hunter2", "elon.musk", "simon.peyton.jones"] regularUsers :: [String] regularUsers = ["alice", "bob", "charlie", "david", "eve", "felicia", "greg", "hailey", "isaac"] ``` -------------------------------- ### Diff-Friendly Import/Export Style Source: https://fourmolu.github.io/config/import-export-style Demonstrates the 'diff-friendly' style for import and export lists, which is the default. This style places each item on a new line, indented. ```Haskell module MyModule ( User (..), createUser, deleteUser, ) where import MyModule.Internal ( User, createUser, deleteUser, ) ``` -------------------------------- ### Load Person Function Definition Source: https://fourmolu.github.io/ Defines a function `loadPerson` which is likely used for loading person data. The snippet shows the start of a function binding and pattern matching. ```Haskell (L (EpAnn (EpaSpan { :(27,1)-(35,72) }) (AnnListItem []) (EpaComments [])) (ValD (NoExtField) (FunBind (NoExtField) (L (EpAnn (EpaSpan { :27:1-10 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: loadPerson})) (MG (FromSource) (L (EpAnn (EpaSpan { :(27,1)-(35,72) }) (AnnList (Nothing) (ListNone) [] (NoEpTok) []) (EpaComments [])) [(L (EpAnn (EpaSpan { :(27,1)-(35,72) }) (AnnListItem []) (EpaComments [])) (Match (NoExtField) (FunRhs (L (EpAnn ``` -------------------------------- ### Set local modules via CLI Source: https://fourmolu.github.io/config/local-modules Use this option to manually define local modules for import grouping when running Ormolu from the command line. This is useful when a Cabal file is not available or needs to be supplemented. ```shell fourmolu Main.hs --import-grouping by-scope --local-modules SomeInternal.Module1 --local-modules SomeModule ``` -------------------------------- ### Manually Specify Ormolu Packages Source: https://fourmolu.github.io/changelog Use the -p or --package option to manually specify packages for Ormolu to infer fixity and precedence information from. This option can be repeated. ```bash -p / --package ``` -------------------------------- ### Diffing Formatted Code Source: https://fourmolu.github.io/ Compares the current code with its formatted version without applying changes. This is helpful for code reviews. ```shell fourmolu --diff src/MyModule.hs ``` -------------------------------- ### Standard Imports with Internal Modules Grouped Source: https://fourmolu.github.io/config/import-grouping Presents a style where standard library imports are listed first, followed by internal modules, and then qualified imports. ```haskell import Control.Monad (Monad (..)) import Control.Monad.State.Lazy (MonadState (..)) import Data.Maybe (maybe) import Data.Text (Text) import Data.Text.IO (hGetLine) import Text.Printf (printf) import qualified Control.Monad.Error as Error import qualified Data.Text import qualified System.IO as SIO import SomeInternal.Module1 (anotherDefinition, someDefinition) import SomeInternal.Module1.SubModuleA import qualified SomeInternal.Module2 as Mod2 ``` -------------------------------- ### Function Signature with Leading Haddock Comments Source: https://fourmolu.github.io/config/haddock-location-signature Demonstrates placing Haddock comments before each argument and the return type when using leading function arrows. ```Haskell func -- | Arg 1 :: Int -- | Arg 2 -> String -- | Return value -> Int ``` -------------------------------- ### Mixed Grouping with Internal Imports Later Source: https://fourmolu.github.io/config/import-grouping Illustrates a grouping where standard library modules are imported first, followed by internal modules, and then qualified imports. ```haskell import Control.Monad (Monad (..)) import qualified Control.Monad.Error as Error import Control.Monad.State.Lazy (MonadState (..)) import Data.Maybe (maybe) import Data.Text (Text) import qualified Data.Text import qualified System.IO as SIO import Text.Printf (printf) import SomeInternal.Module1 (anotherDefinition, someDefinition) import SomeInternal.Module1.SubModuleA import qualified SomeInternal.Module2 as Mod2 ``` -------------------------------- ### Type Signature with Leading Arguments Arrow Style Source: https://fourmolu.github.io/config/function-arrows Shows the type signature with the `leading-args` arrow style, which places the arrow at the beginning of the line, similar to `leading`, but with specific handling for arguments. ```haskell show2WithLabel :: forall a b. (Show a, Show b) => String -> (a, b) -> String ``` -------------------------------- ### Grouped Qualified Imports Last Source: https://fourmolu.github.io/config/import-grouping Shows an import style where standard and specific imports come first, followed by qualified imports grouped at the end. ```haskell import Control.Monad (Monad (..)) import Control.Monad.State.Lazy (MonadState (..)) import Data.Maybe (maybe) import Data.Text (Text) import Data.Text.IO (hGetLine) import SomeInternal.Module1 (anotherDefinition, someDefinition) import SomeInternal.Module1.SubModuleA import Text.Printf (printf) import qualified Control.Monad.Error as Error import qualified Data.Text import qualified SomeInternal.Module2 as Mod2 import qualified System.IO as SIO ``` -------------------------------- ### Code Formatting with 80 Character Limit Source: https://fourmolu.github.io/config/column-limit This snippet illustrates code formatting with an 80-character column limit. Lines are broken to adhere to this limit, showing a different breaking strategy than a tighter limit. ```haskell rootUsers :: [String] rootUsers = ["root"] adminUsers :: [String] adminUsers = ["hunter2", "elon.musk", "simon.peyton.jones"] regularUsers :: [String] regularUsers = [ "alice" , "bob" , "charlie" , "david" , "eve" , "felicia" , "greg" , "hailey" , "isaac" ] ``` -------------------------------- ### Type Signature with Leading Arrow Style Source: https://fourmolu.github.io/config/function-arrows Illustrates the type signature using the `leading` arrow style, where the arrow is placed at the beginning of the line. ```haskell show2WithLabel :: forall a b . (Show a, Show b) => String -> (a, b) -> String ``` -------------------------------- ### Configure Operator Fixities in fourmolu.yaml Source: https://fourmolu.github.io/changelog Define custom operator fixities and precedences in the fourmolu.yaml configuration file. This is an alternative to using a .ormolu file. ```yaml fixities: - 'infixr 8 .=' - 'infixr 5 #' ``` -------------------------------- ### Align 'in' Keyword Left with 'let' Source: https://fourmolu.github.io/config/in-style Illustrates the `left-align` style for the 'in' keyword. This option aligns the 'in' keyword directly under the 'let' keyword. ```haskell testUser = let name = "Alice" age = 30 in User name age ``` -------------------------------- ### Without Indented Wheres Source: https://fourmolu.github.io/config/indent-wheres Demonstrates the default behavior where 'where' bindings are half-indented relative to the preceding code body. ```Haskell setPassword :: String -> String -> IO () setPassword username password = do user <- getUser username >>= maybe userNotFound pure hash <- hashPassword password saveUser user{userPasswordHash = hash} where userNotFound = error $ "User not found: " ++ username ``` -------------------------------- ### No Space Between 'let' and 'in' Source: https://fourmolu.github.io/config/in-style Shows the `no-space` style for the 'in' keyword. This option removes any extra space between the 'let' binding and the 'in' keyword. ```haskell testUser = let name = "Alice" age = 30 in User name age ``` -------------------------------- ### Haskell Abstract Syntax Tree (AST) Representation Source: https://fourmolu.github.io/ This snippet represents a fragment of a Haskell Abstract Syntax Tree (AST). It details the structure of a module, including its name, imports, and exported entities. ```haskell (HsModule (XModulePs (EpAnn (EpaSpan { :1:1 }) (AnnsModule (NoEpTok) (EpTok (EpaSpan { :6:1-6 })) (EpTok (EpaSpan { :12:3-7 })) [] [] (Just ((,) { :36:1 } { :35:72 }))))) (EpaCommentsBalanced [(L (EpaSpan { :1:1-30 }) (EpaComment (EpaBlockComment "{-# LANGUAGE UnicodeSyntax #-}") { :1:1 })) ,(L (EpaSpan { :(3,1)-(5,2) }) (EpaComment (EpaDocComment (NestedDocString (HsDocStringNext) (L { :(3,5)-(5,2) } (HsDocStringChunk " This is the\nperson module.\n")))) { :1:1-30 }))] [])) (EpVirtualBraces (1)) (Nothing) (Just (L { :(3,1)-(5,2) } (WithHsDocIdentifiers (NestedDocString (HsDocStringNext) (L { :(3,5)-(5,2) } (HsDocStringChunk " This is the\nperson module.\n"))) [])))) (Just (L (EpAnn (EpaSpan { :6:8-13 }) (AnnListItem []) (EpaComments [])) {ModuleName: Person})) (Just (L (EpAnn (EpaSpan { :(6,15)-(12,1) }) (AnnList (Nothing) (ListParens (EpTok (EpaSpan { :6:15 })) (EpTok (EpaSpan { :12:1 }))) [] ((,) (NoEpTok) []) []) (EpaComments []) [(L (EpAnn (EpaSpan { :(7,5)-(10,5) }) (AnnListItem [(AddCommaAnn (EpTok (EpaSpan { :10:6 })))]) (EpaComments []) (IEThingWith ((,) (Nothing) ((,,,) (EpTok (EpaSpan { :7:12 })) (NoEpTok) (NoEpTok) (EpTok (EpaSpan { :10:5 }))))) (L (EpAnn (EpaSpan { :7:5-10 }) (AnnListItem []) (EpaComments []) (IEName (NoExtField) (L (EpAnn (EpaSpan { :7:5-10 }) (NameAnnTrailing []) (EpaComments []) ) (Unqual {OccName: Person})))) (NoIEWildcard) [(L (EpAnn (EpaSpan { :8:9-14 }) (AnnListItem [(AddCommaAnn (EpTok (EpaSpan { :8:15 })))]) (EpaComments []) ) (IEName (NoExtField) (L (EpAnn (EpaSpan { :8:9-14 }) (NameAnnTrailing []) (EpaComments []) ) (Unqual {OccName: Person})))) ,(L (EpAnn (EpaSpan { :9:9-12 }) (AnnListItem []) (EpaComments []) ) (IEName (NoExtField) (L (EpAnn (EpaSpan { :9:9-12 }) (NameAnnTrailing []) (EpaComments []) ) (Unqual {OccName: name}))))] (Nothing))) ,(L (EpAnn (EpaSpan { :11:5-14 }) (AnnListItem [(AddCommaAnn (EpTok (EpaSpan { :11:15 })))]) (EpaComments []) ) (IEVar (Nothing) (L (EpAnn (EpaSpan { :11:5-14 }) (AnnListItem []) (EpaComments []) ) (IEName (NoExtField) (L (EpAnn (EpaSpan { :11:5-14 }) (NameAnnTrailing []) (EpaComments []) ) (Unqual {OccName: loadPerson})))) (Nothing)))])) [(L (EpAnn (EpaSpan { :(14,1)-(18,2) }) (AnnListItem []) (EpaComments []) ) (ImportDecl (XImportDeclPass (EpAnn (EpaSpan { :(14,1)-(18,2) }) (EpAnnImportDecl (EpTok (EpaSpan { :14:1-6 })) (Nothing) ``` -------------------------------- ### Basic Import Grouping Rule Definition Source: https://fourmolu.github.io/config/import-grouping A simple rule definition for an import group, specifying a name and a glob pattern for matching modules. ```yaml name: "Text modules" rules: - glob: Data.Text ``` -------------------------------- ### KNR Record Style Source: https://fourmolu.github.io/config/record-style Illustrates the 'knr' (Kernighan and Ritchie) style for record declarations and default values. Braces are placed on the same line as the record definition. ```Haskell data User = User { userName :: String, userAge :: Int, userActive :: Bool } defaultUser = User { userName = "", userAge = -1, userActive = false } ``` -------------------------------- ### Trailing Import/Export Style Source: https://fourmolu.github.io/config/import-export-style Shows the 'trailing' style for import and export lists. This style places each item on a new line, with a trailing comma on the last item. ```Haskell module MyModule ( User (..), createUser, deleteUser, ) where import MyModule.Internal ( User, createUser, deleteUser, ) ``` -------------------------------- ### Haskell Module Declaration with Language Extension Source: https://fourmolu.github.io/ This snippet shows a basic Haskell module declaration with the UnicodeSyntax language extension enabled. It includes documentation comments for the module. ```haskell {-# LANGUAGE UnicodeSyntax #-} -- | This is the -- person module. module Person where ``` -------------------------------- ### Function Signature with Trailing Haddock Comments (Haddock '^') Source: https://fourmolu.github.io/config/haddock-location-signature Shows how to use the '^' syntax for Haddock comments placed after the type they describe, with leading function arrows. ```Haskell func :: Int -- ^ Arg 1 -> String -- ^ Arg 2 -> Int -- ^ Return value ``` -------------------------------- ### Type Signature with Trailing Arrow Style Source: https://fourmolu.github.io/config/function-arrows Demonstrates the type signature with the default `trailing` arrow style, where the arrow is placed at the end of the line. ```haskell show2WithLabel :: forall a b. (Show a, Show b) => String -> (a, b) -> String ``` -------------------------------- ### Two Newlines Between Declarations Source: https://fourmolu.github.io/config/newlines-between-decls This snippet demonstrates how to configure two newlines between top-level declarations. ```haskell newtype Username = Username String newtype Password = Password String ``` -------------------------------- ### Haskell AST Representation Source: https://fourmolu.github.io/ This snippet shows a Haskell Abstract Syntax Tree (AST) representation, likely for parsing or code analysis. It details annotations, spans, and variable occurrences. ```haskell (AnnListItem []) (EpaComments []) (HsVar (NoExtField) (L (EpAnn (EpaSpan { :21:47-50 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: show}))))) (L (EpAnn (EpaSpan { :21:52-55 }) (AnnListItem []) (EpaComments [])) (HsVar (NoExtField) (L (EpAnn (EpaSpan { :21:52-55 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: rows})))))))] (EmptyLocalBinds (NoExtField)))))]))))] [])) (L (EpAnn (EpaSpan { :21:60-71 }) (AnnListItem []) (EpaComments [])) (HsApp (NoExtField) (L (EpAnn (EpaSpan { :21:60-69 }) (AnnListItem []) (EpaComments [])) (HsVar (NoExtField) (L (EpAnn (EpaSpan { :21:60-69 }) (NameAnnTrailing []) (EpaComments [])) (Unqual {OccName: logAndFail})))) (L (EpAnn (EpaSpan { :21:71 }) (AnnListItem []) (EpaComments [])) (HsVar (NoExtField) (L (EpAnn (EpaSpan { :21:71 }) (NameAnnTrailing []) (EpaComments [])))))))))] ``` -------------------------------- ### Load Person Function Source: https://fourmolu.github.io/ This snippet defines a function to load a person, likely used for data retrieval or initialization. It involves pattern matching and potentially a query execution mechanism. ```haskell loadPerson :: Person loadPerson = id ```