Contents
- Whence come definitions
- Imports from packages
- Exposed and hidden packages
- The home package
- The target set
- Star imports
- The automatic star
- The state of GHCi
- Reloading
- Overview of commands
- Deferring type errors
We’ll next look at bringing a file or project into scope in a GHCi session, which we do primarily using the :load
and :reload
commands.
In a Haskell source file, what’s in scope is determined entirely by the list of import
statements at the top of the module. We can type import
statements into the GHCi prompt too, but GHCi also gives us additional ways to bring code into scope. These features make the scope at the prompt flexible, dynamic, and consequently more complicated.
Overall, there are two routes by which things come into scope in GHCi: either you typed them in at the prompt, or they were imported. Understanding the latter is a little tricky, as there are several ways that imports can happen.
- The
:load
,:reload
,:add
,:unadd
commands that manipulate the target set; - Using
import
and:module
to bring modules into and out of scope; - Using the
-package
GHC option and:set -package
within GHCi to expose hidden packages; and - What
*
means before a module name.