Skip to content

Haskell GHCi Guide — Interactive REPL, Debugging, and Exploration

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about Haskell GHCi Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Haskell GHCi is the interactive REPL for type exploration (:t), expression evaluation, debugging with breakpoints (:break, :step, :continue), and profiling with :set +s for timing and :set +c for allocation statistics.

Starting GHCi

# Start REPL
ghci

# Load file
:load Main.hs

# Load with package
ghci -package text

# With project context
cabal repl
stack ghci

Type Exploration

-- Check types
:t map
-- map :: (a -> b) -> [a] -> [b]

:t foldl'
-- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b

:t (+)
-- (+) :: Num a => a -> a -> a

:info Maybe
-- data Maybe a = Nothing | Just a

Debugging

-- Set breakpoint
:break 42  -- line 42
:break Main.functionName

-- List breakpoints
:show breaks

-- Step through
:step
:steplocal
:continue

-- Trace
:trace myFunction

Interactive Evaluation

-- Evaluate and show type
> 2 + 2
4

> :type it
it :: Num a => a

-- Timing
:set +s
> sum [1..1000000]
500000500000
(0.02 secs, 42,000 bytes)

:unset +s

Commands

-- Useful commands
:?                    -- help
:load / :l           -- load file
:reload / :r         -- reload
:module / :m         -- show loaded modules
:browse ModuleName   -- list exports
:kind Maybe          -- * -> *
:set -XOverloadedStrings  -- enable extension
:script file.hs      -- run script

Common Mistakes

1. Forgetting :load

GHCi starts with Prelude only. Use :load File.hs to load your source.

2. Confusing GHCi directives with Haskell code

Commands start with :. Expressions are plain Haskell. let x = 5 in GHCi defines a variable.

3. Not using multiline mode

Paste multi-line code with :{ and :} or use :set +m for automatic indentation detection.

Practice Questions

1. How do you check the type of an expression in GHCi? :t expression or :type expression. Shows the polymorphic type.

2. How do you set a breakpoint? :break line-number or :break ModuleName.functionName. Then :continue to run.

3. How do you measure execution time? :set +s enables timing and allocation stats. Every evaluation shows time and memory.

FAQ

{{< faq question="Can I define functions in GHCi?" >}} Yes. Use let f x = x * 2 or multi-line with :{ ... :}. Functions are defined for the session. {{< /faq >}}

{{< faq question="How do I load multiple modules?" >}} :load File1.hs File2.hs loads them together. All public definitions are available. {{< /faq >}}

{{< faq question="What does :browse do?" >}} :browse ModuleName lists all exports of a module. Useful for discovering available functions. {{< /faq >}}

What's Next

Now learn about GADTs.

Topic Description Link
GADTs Generalized algebraic data types {{< ref "28-gadt" >}}
Type Families Type-level functions {{< ref "29-type-families" >}}

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro