hx repl

Start an interactive GHCi session.

Synopsis

hx repl [OPTIONS] [COMPONENT]

Description

The repl command starts GHCi with your project loaded. You can interactively explore your code, test functions, and experiment with ideas.

Options

    --no-build          Don't rebuild before starting REPL
    --ghci-options      Additional options to pass to GHCi
-v, --verbose           Show REPL startup details

Arguments

COMPONENT              Component to load (lib, exe:name, test:name)

Examples

Start REPL with Library

# Load the library
hx repl

Load Specific Component

# Load an executable
hx repl exe:my-app

# Load tests
hx repl test:my-tests

Skip Rebuild

hx repl --no-build

Custom GHCi Options

hx repl --ghci-options="-XOverloadedStrings -XDeriveGeneric"

Using the REPL

Once in the REPL, you can:

Import Your Modules

ghci> import MyProject
ghci> import MyProject.Parser

Test Functions

ghci> parse "test input"
Right (ParsedData {...})

ghci> process [1, 2, 3]
[2, 4, 6]

Check Types

ghci> :type parse
parse :: String -> Either ParseError ParsedData

ghci> :info Maybe
data Maybe a = Nothing | Just a

Browse Modules

ghci> :browse MyProject
parse :: String -> Either ParseError ParsedData
process :: [Int] -> [Int]
Config(..)

Reload Changes

ghci> :reload

Useful GHCi Commands

CommandDescription
:reload / :rReload modified modules
:type expr / :tShow expression type
:info name / :iInfo about name
:browse ModuleList module exports
:quit / :qExit GHCi
:help / :?Show help

Configuration

Configure REPL behavior in hx.toml:

[repl]
# Default component to load
default = "lib"

# Load these modules automatically
auto-load = ["MyProject", "MyProject.Prelude"]

# GHCi options
ghci-options = ["-XOverloadedStrings"]

# Custom .ghci file
ghci-conf = ".ghci"

Custom .ghci File

Create a .ghci file in your project root:

-- .ghci
:set prompt "λ> "
:set prompt-cont "| "
:set -XOverloadedStrings
:set -XDeriveGeneric
import Data.Text (Text)

REPL Workflows

Exploratory Development

  1. Start REPL: hx repl
  2. Write functions in your source files
  3. Reload: :reload
  4. Test interactively
  5. Repeat

Testing Ideas

-- Test a function idea quickly
ghci> let quickSort [] = []
ghci>     quickSort (x:xs) = quickSort smaller ++ [x] ++ quickSort larger
ghci>       where smaller = filter (< x) xs
ghci>             larger = filter (>= x) xs
ghci> quickSort [3, 1, 4, 1, 5, 9, 2, 6]
[1,1,2,3,4,5,6,9]

Debugging

ghci> import Debug.Trace
ghci> :set -fbreak-on-exception
ghci> myFunction input
*** Exception: ...
ghci> :back
ghci> :list

See Also