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 detailsArguments
COMPONENT Component to load (lib, exe:name, test:name)Examples
Start REPL with Library
# Load the library
hx replLoad Specific Component
# Load an executable
hx repl exe:my-app
# Load tests
hx repl test:my-testsSkip Rebuild
hx repl --no-buildCustom 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.ParserTest 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 aBrowse Modules
ghci> :browse MyProject
parse :: String -> Either ParseError ParsedData
process :: [Int] -> [Int]
Config(..)Reload Changes
ghci> :reloadUseful GHCi Commands
| Command | Description |
|---|---|
:reload / :r | Reload modified modules |
:type expr / :t | Show expression type |
:info name / :i | Info about name |
:browse Module | List module exports |
:quit / :q | Exit 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
- Start REPL:
hx repl - Write functions in your source files
- Reload:
:reload - Test interactively
- 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