haskell-project-structure
Project layout, module design, and cabal configuration for pragmatic Haskell. Use when creating a new package, organising modules, configuring a cabal file, or structuring a multi-package monorepo.
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install pragmatic-haskell-haskell-project-structureManual setup by platform
Claude Code
~/.claude/skills/pragmatic-haskell-haskell-project-structure/SKILL.md
Instructions
Project Structure
Standard Directory Layout
myapp/
├── myapp.cabal
├── cabal.project -- only for monorepos; omit for single packages
├── src/ -- library source
│ └── MyApp/
│ ├── Domain/
│ │ ├── Types.hs
│ │ └── Service.hs
│ └── Infra/
│ └── Store.hs
├── app/ -- executable entry point(s)
│ └── Main.hs
├── test/ -- test helper library (exposed-modules)
│ └── MyApp/
│ └── Test/
│ ├── Generators.hs
│ ├── Fixtures.hs
│ └── MockStore.hs
├── test-main/ -- test runner executable
│ └── Main.hs
└── bench/ -- optional benchmarks
└── Main.hs
Keep app/ thin: Main.hs parses CLI arguments, builds the Env, and calls
into the library. All logic belongs in src/.
Module Naming
Use a MyApp.Domain.Concept hierarchy. Never use flat module names.
-- Good
MyApp.User.Types
MyApp.User.Service
MyApp.User.Validation
MyApp.Payment.Types
MyApp.Payment.Service
-- Bad — flat, no hierarchy
Types
UserService
Validation
Each domain area gets its own subdirectory. Types.hs holds data types and
smart constructors for that domain. Service.hs holds the business logic.
Store.hs (or Repository.hs) holds the persistence interface.
Keep modules focused. A module that imports from 20 other modules in the same
package is doing too much.
Explicit Export Lists
Every module must have an explicit export list. Never use implicit exports
(module Foo where with no list).
module MyApp.User.Types
( -- * Types
User (..)
, UserId -- opaque
, unUserId
-- * Construction
, mkUserId
, mkUser
) where
Opaque types (types whose constructors are intentionally hidden) should be
annotated with -- opaque on the same line as the type name in the export
list. This makes it clear to readers that the constructor is hidden by design,
not by accident:
module MyApp.Email
( Email -- opaque
, mkEmail
, emailText
) where
Re-exports: when re-exporting from another module, group re-exports
together and label the source with a comment.
Import Ordering
Imports are ordered in three groups, separated by blank lines:
Prelude/NoImplicitPreludereplacement (if any)baseand standard library modules, then third-party packages- Internal (
MyApp.*) modules
Within each group, imports are alphabetically ordered. Qualified imports
use ImportQualifiedPost style (import Data.Map.Strict qualified as Map).
module MyApp.User.Service
( createUser
, fetchUser
) where
import Prelude
import Control.Exception (throwIO)
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Text (Text)
import MyApp.User.Store (UserStore (..))
import MyApp.User.Types (User (..), UserId (..))
Never use import Module (everything individually) for modules with many
exports — use a qualified import instead.
Section Headers
Use section headers to separate logical groups within a module. Follow the
Haddock section format so they appear in generated documentation:
-- ---------------------------------------------------------------------------
-- * Types
-- ---------------------------------------------------------------------------
data User = User { ... }
-- ---------------------------------------------------------------------------
-- * Construction
-- ---------------------------------------------------------------------------
mkUser :: Text -> Email -> User
mkUser = ...
-- ---------------------------------------------------------------------------
-- * Queries
-- ---------------------------------------------------------------------------
isActive :: User -> Bool
isActive = ...
Use -- ---------------------------------------------------------------------------
as the separator (80 dashes). Use -- * for top-level sections.
Warning Flags
Every library and executable stanza must include these warning flags:
ghc-options:
-Wall
-Wcompat
-Wredundant-constraints
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-deriving-strategies
-Wpartial-fields
-Widentities
-Wmissing-export-lists
-Wunused-packages
Use a common stanza to share them:
common warnings
ghc-options:
-Wall
-Wcompat
-Wredundant-constraints
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-deriving-strategies
-Wpartial-fields
-Widentities
-Wmissing-export-lists
-Wunused-packages
Then import: warnings in each stanza.
Never suppress warnings with -Wno-* flags in production code.
-Wno-incomplete-uni-patterns and -Wno-partial-fields are banned. Fix the
code.
GHC Options
common defaults
default-language: GHC2021
default-extensions: NoImplicitPrelude
Only NoImplicitPrelude goes in default-extensions. All other extensions
are declared per-module with {-# LANGUAGE ... #-}.
Multi-Package Monorepo
For multi-package projects, use cabal.project at the root:
-- cabal.project
packages:
myapp-core/
myapp-api/
myapp-cli/
myapp-test-utils/
Or use a glob:
packages: */
When to split packages:
| Split when | Keep together when |
|---|---|
| Another team or project needs to depend on a subset | All code is consumed together |
| Two components have incompatible dependency sets | Dependencies are the same throughout |
| A component has a stable, versioned API boundary | The API is still in flux |
| Build times are dominated by unnecessary transitive rebuilds | The build is already fast |
A common split: myapp-core (pure domain types and logic, minimal deps),
myapp-db (persistence, depends on postgresql-simple etc.),
myapp-server (HTTP layer), myapp-cli (command-line entry point).
Haddock Conventions
Every module must have a module-level Haddock header placed directly above
the module M where line, below any {-# OPTIONS_GHC #-} pragmas:
{-# OPTIONS_GHC -fno-warn-orphans #-}
{- |
Module : MyApp.Payment.Service
Description : Business logic for payment processing.
-}
module MyApp.Payment.Service
( processPayment
, PaymentError (..)
) where
For individual definitions:
- Every exported type and function has a Haddock comment.
- Use
-- |for the first line. Multi-line comments use--on continuation
lines (no leading|). - Document the why, not the what.
-- | The user identifieris
redundant.-- | Opaque identifier; use 'mkUserId' to constructis useful. - Use
-- ^for field documentation inline with record fields.
-- | Configuration for the payment gateway.
-- Constructed from environment variables at startup.
data GatewayConfig = GatewayConfig
{ gcEndpoint :: !Text -- ^ Base URL for the gateway API
, gcApiKey :: !Text -- ^ API key; treat as a secret
, gcTimeout :: !Int -- ^ Request timeout in seconds
} deriving stock (Eq, Show)
Long-Lived Data and Space Leaks
For data structures that live for the duration of the application (in-memory
caches, mutable state vars, session stores), consider using the nothunks
library to assert the absence of unexpected thunks in tests:
import NoThunks.Class (NoThunks, noThunks)
data Cache k v = Cache
{ cacheMap :: !(Map k v)
, cacheSize :: !Int
} deriving stock (Show)
deriving anyclass (NoThunks)
-- In a test:
it "Cache contains no unexpected thunks" $ do
let c = buildCache someData
result <- noThunks [] c
result `shouldBe` Nothing
This catches space leaks from unevaluated thunks accumulating in long-lived
structures before they surface as memory problems in production.
See references/project-structure-examples.md for complete worked examples.
Security
Reviews (0)
More from Pragmatic Haskell
View source →More Build skills
Browse category →Frequently asked questions about haskell-project-structure
What does the haskell-project-structure skill do?
Project layout, module design, and cabal configuration for pragmatic Haskell. Use when creating a new package, organising modules, configuring a cabal file, or structuring a multi-package monorepo. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the haskell-project-structure skill?
Run `npx @skills-hub-ai/cli install pragmatic-haskell-haskell-project-structure` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/pragmatic-haskell-haskell-project-structure/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does haskell-project-structure work with?
haskell-project-structure runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the haskell-project-structure skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use haskell-project-structure after installing it?
In Claude Code, type `/pragmatic-haskell-haskell-project-structure` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the haskell-project-structure skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.