Compiler Backends

hx supports multiple Haskell compiler backends, allowing you to choose the best compiler for your use case.

Overview

hx provides a unified interface for different compilers:

BackendDescriptionBest For
GHCStandard Haskell compilerMost projects, libraries
BHCBasel Haskell CompilerNumerical computing, ML

GHC Backend (Default)

GHC (Glasgow Haskell Compiler) is the standard Haskell compiler and the default backend.

Configuration

[compiler]
backend = "ghc"

[compiler.ghc]
version = "9.8.2"
options = ["-Wall", "-Wextra"]

Usage

# Build with GHC (default)
hx build

# Explicitly specify GHC
hx build --backend ghc

GHC Features

  • Full Haskell 2010 and GHC extensions support
  • Excellent optimization (-O2)
  • Mature ecosystem support
  • HLS (Haskell Language Server) integration
  • Extensive profiling tools

BHC Backend

BHC (Basel Haskell Compiler) is an alternative compiler optimized for numerical computing and machine learning workloads.

Configuration

[compiler]
backend = "bhc"

[compiler.bhc]
profile = "numeric"          # Optimization profile
emit_kernel_report = true    # Generate optimization reports
tensor_fusion = true         # Enable tensor fusion
target = "aarch64-linux-gnu" # Cross-compilation target

Usage

All major commands support the BHC backend:

# Build with BHC
hx build --backend bhc

# Test with BHC
hx test --backend bhc

# Run with BHC
hx run --backend bhc

# Set in hx.toml to always use BHC
# [compiler]
# backend = "bhc"

BHC Profiles

BHC offers specialized optimization profiles:

Default Profile

[compiler.bhc]
profile = "default"

Balanced optimization for general use.

Server Profile

[compiler.bhc]
profile = "server"

Optimized for:

  • Long-running processes
  • High throughput
  • Consistent latency

Numeric Profile

[compiler.bhc]
profile = "numeric"

Optimized for:

  • Numerical computation
  • Array operations
  • Linear algebra
  • Machine learning workloads

Features:

  • Tensor fusion
  • SIMD optimizations
  • Efficient array representations

Edge Profile

[compiler.bhc]
profile = "edge"

Optimized for:

  • Small binary size
  • Low memory usage
  • Embedded systems
  • Edge computing

BHC-Specific Options

Kernel Reports

Generate reports on kernel optimization:

[compiler.bhc]
emit_kernel_report = true

Reports are written to .hx/bhc-reports/.

Tensor Fusion

Enable automatic tensor operation fusion:

[compiler.bhc]
tensor_fusion = true

This optimizes chains of array operations.

BHC Targets

BHC supports these compilation targets:

TargetDescription
x86_64-linux-gnuLinux x86_64
aarch64-linux-gnuLinux ARM64
x86_64-apple-darwinmacOS Intel
aarch64-apple-darwinmacOS Apple Silicon
wasm32-wasiWebAssembly
riscv64-linux-gnuRISC-V 64-bit

Switching Backends

Per-Command

Override the configured backend for a single command:

hx build --backend ghc
hx build --backend bhc

Per-Project

Set in hx.toml:

[compiler]
backend = "bhc"

Per-Environment

Use environment variables:

export HX_BACKEND=bhc
hx build

Backend Comparison

Compilation Speed

BackendDebugRelease
GHCFastModerate
BHCModerateFast (for numeric)

Runtime Performance

WorkloadGHCBHC
GeneralExcellentGood
NumericGoodExcellent
ParsingExcellentGood
ML/ArraysGoodExcellent

Binary Size

BackendSize
GHCModerate
BHC (edge)Small

Ecosystem Support

FeatureGHCBHC
Hackage packagesAllMost
HLSYesNo
ProfilingExtensiveBasic
Template HaskellYesLimited

Installing Backends

Install GHC

hx toolchain install --ghc 9.8.2

Install BHC

hx toolchain install --bhc 0.2.0

List Installed

hx toolchain list

Use Cases

Use GHC When

  • Building libraries for Hackage
  • Needing full Template Haskell support
  • Using HLS for IDE features
  • Maximum ecosystem compatibility
  • Detailed profiling needed

Use BHC When

  • Building ML/data science applications
  • Heavy numerical computation
  • Targeting WebAssembly
  • Optimizing for embedded/edge
  • Cross-compiling to ARM

BHC Platform Snapshots

BHC Platform provides curated package sets — the BHC equivalent of Stackage. Each snapshot contains packages verified to build and work together under BHC.

Configuration

[compiler]
backend = "bhc"

[bhc-platform]
snapshot = "bhc-platform-2026.1"

CLI Commands

# List available snapshots
hx bhc-platform list

# Show snapshot details
hx bhc-platform info bhc-platform-2026.1

# Show all packages in a snapshot
hx bhc-platform info bhc-platform-2026.1 --packages

# Set snapshot for current project
hx bhc-platform set bhc-platform-2026.1

Lock Integration

When a BHC Platform snapshot is configured, hx lock pins package versions from the snapshot into the resolver, providing reproducible builds without manually specifying constraints.

See hx bhc-platform for the full command reference.

BHC Project Templates

hx includes project templates optimized for BHC:

# Numeric computing (hmatrix, vector, massiv, statistics)
hx new numeric my-science

# Web server (Servant, Warp, WAI)
hx new server my-api

You can also create standard templates with BHC:

hx init --backend bhc
hx new webapp my-app --backend bhc
hx new cli my-tool --backend bhc
hx new library my-lib --backend bhc

Example: ML Project

A project using BHC for ML workloads:

# hx.toml
[project]
name = "ml-classifier"

[compiler]
backend = "bhc"

[compiler.bhc]
profile = "numeric"
tensor_fusion = true
emit_kernel_report = true

[bhc-platform]
snapshot = "bhc-platform-2026.1"

[build]
release = true
# Build optimized ML binary
hx build --release

# Test
hx test

# Run
hx run -- --input data.csv

# Check optimization report
cat .hx/bhc-reports/kernel-report.txt

See Also