This guide will walk you through creating and building your first Haskell project with hx.
Prerequisites
Before starting, make sure you have:
- hx installed
- A Haskell toolchain (GHC + Cabal)
If you don’t have a Haskell toolchain, install it with:
hx toolchain installCreate a New Project
Create a new Haskell project with sensible defaults:
hx new my-project
cd my-projectThis creates a project with the following structure:
my-project/
├── app/
│ └── Main.hs # Application entry point
├── src/
│ └── MyProject.hs # Library source
├── test/
│ └── Spec.hs # Test suite
├── my-project.cabal # Cabal package description
├── hx.toml # hx configuration
└── README.mdProject Templates
hx supports different project templates:
# Default: library + executable + tests
hx new my-project
# Library only
hx new my-lib --lib
# Executable only
hx new my-app --exe
# Minimal setup
hx new my-minimal --minimalSpecialized Templates
# Web application
hx new webapp my-app
# CLI tool
hx new cli my-tool
# Numeric computing (BHC backend, hmatrix, vector, massiv)
hx new numeric my-science
# Web server (BHC backend, Servant, Warp, WAI)
hx new server my-apiThe numeric and server templates use the BHC backend with optimized profiles. See Compiler Backends for more on BHC.
Build Your Project
Compile your project:
hx buildFor optimized release builds:
hx build --releaseBuild output is placed in the dist-newstyle directory (Cabal’s default).
Run Your Project
Run the executable:
hx runPass arguments to your program:
hx run -- --help
hx run -- arg1 arg2For projects with multiple executables:
hx run --exe my-other-exeAdd Dependencies
Add packages to your project:
# Add a single package
hx add text
# Add multiple packages
hx add text containers aeson
# Add with version constraint
hx add "aeson >=2.0 && <2.2"
# Add as dev dependency (test/benchmark only)
hx add --dev hspec QuickCheckDependencies are added to your .cabal file automatically.
Generate Lockfile
Create a lockfile for reproducible builds:
hx lockThis creates hx.lock with pinned versions of all dependencies.
Run Tests
Execute your test suite:
hx testRun specific tests:
# Run tests matching a pattern
hx test --match "Parser"
# Run a specific test component
hx test --test my-project-testStart the REPL
Launch an interactive GHCi session with your project loaded:
hx replThe REPL loads your library modules, making them available for interactive exploration:
ghci> import MyProject
ghci> :type someFunctionType Check Without Building
Quickly check your code for errors without a full build:
hx checkThis is faster than hx build and is useful during development.
Format and Lint
Format your Haskell code:
hx fmtRun the linter:
hx lintWatch Mode
Automatically rebuild when files change:
# Watch and rebuild
hx watch build
# Watch and run tests
hx watch test
# Watch and run the project
hx watch runCheck Your Environment
Diagnose toolchain issues:
hx doctorThis checks for:
- GHC installation and version
- Cabal installation
- GHCup availability
- HLS compatibility
- System dependencies
What’s Next?
- Learn about all available commands
- Configure your project with hx.toml
- Explore advanced features
- Read the workflow guides