Skip to content

Commit 7058221

Browse files
committed
Tidy up REPL environment documentation
1 parent f76a9f9 commit 7058221

File tree

5 files changed

+101
-73
lines changed

5 files changed

+101
-73
lines changed

doc/GUIDE.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,17 +1343,20 @@ stack exec ghci
13431343
~~~
13441344

13451345
But that won't load up locally written modules for access. For that, use the
1346-
`stack ghci` command or its synonym `stack repl`. To then load modules from your
1347-
project, use the `:m` command (for "module") followed by the module name.
1346+
`stack ghci` or `stack repl` commands, which are equivalent. To then load
1347+
modules from your project in GHCi, use the `:module` command (`:m` for short)
1348+
followed by the module name.
13481349

13491350
!!! note
13501351

1351-
If you have added upstream packages to your project please make sure to mark
1352-
them as *dependency package*s for faster and reliable usage of `stack ghci`.
1353-
Otherwise GHCi may have trouble due to conflicts of compilation flags or
1354-
having to unnecessarily interpret too many modules. See
1355-
[stack.yaml documentation](yaml_configuration.md#packages) to learn how to
1356-
mark a package as a *dependency package*.
1352+
If you have added packages to your project please make sure to mark them as
1353+
extra deps for faster and reliable usage of `stack ghci`. Otherwise GHCi may
1354+
have trouble due to conflicts of compilation flags or having to
1355+
unnecessarily interpret too many modules. See Stack's project-level
1356+
[configuration](yaml_configuration.md#extra-deps) to learn how to
1357+
configure a package as an extra-dep.
1358+
1359+
For further information, see the [REPL environment](ghci.md) documentation.
13571360

13581361
## The `stack ghc` and `stack runghc` commands
13591362

doc/build_command.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ Unset the flag to disable this behaviour. When disabled:
264264
console noise. If you would like to see this content instead, you can use
265265
the `dump-logs` option.
266266

267+
### The `stack build --pedantic` flag
268+
269+
Pass the flag to build your project with the GHC options `-Wall` and `-Werror`.
270+
`-Wall` turns on all warning options that indicate potentially suspicious code.
271+
`-Werror` makes any warning into a fatal error.
272+
267273
### The `stack build --watch-all` flag
268274

269275
Pass the flag to rebuild your project every time any local file changes (from

doc/ghci.md

Lines changed: 81 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,108 @@
11
<div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div>
22

3-
# GHCi
4-
5-
`stack ghci` allows you to load components and files of your project into
6-
`ghci`. It uses the same TARGET syntax as `stack build`, and can also take
7-
options like `--test`, `--bench`, and `--flag`. Similarly to `stack build`, the
8-
default is to load up ghci with all libraries and executables in the project.
9-
10-
In order to load multiple components, `stack ghci` combines all of the ghc options
11-
together. This doesn't work in the general case, but when the packages being
12-
loaded share similar conventions, it should work out. A common source of issues
13-
is when one component defines default extensions which aren't assumed by another
14-
component. For example, specifying `NoImplicitPrelude` in one component but
15-
not another is quite likely to cause failures. `ghci` will be run with
3+
# REPL environment
4+
5+
A read–evaluate–print loop (REPL) environment takes single user inputs, executes
6+
them, and returns the result to the user. GHCi is GHC's interactive environment.
7+
The `stack ghci` or `stack repl` commands, which are equivalent, allow you to
8+
load components and files of your project into GHCi.
9+
10+
The command uses the same TARGET syntax as `stack build`. It can also take flags
11+
like `--test` and `--bench` and options like `--flag`. Similarly to
12+
`stack build`, the default is to load up GHCi with all libraries and executables
13+
in the project.
14+
15+
In order to load multiple components, `stack ghci` combines all of the GHC
16+
options together. This doesn't work in the general case, but when the packages
17+
being loaded share similar conventions, it should work out. A common source of
18+
issues is when one component defines default extensions which aren't assumed by
19+
another component. For example, specifying `NoImplicitPrelude` in one component
20+
but not another is quite likely to cause failures. GHCi will be run with
1621
`-XNoImplicitPrelude`, but it is likely that modules in the other component
17-
assume that the Prelude is implicitly imported.
22+
assume that the `Prelude` is implicitly imported.
1823

1924
## Selecting Main module
2025

2126
When loading multiple packages, there may be multiple definitions for the `Main`
22-
module. You can specify which Main module to load by passing in the
23-
`--main-is TARGET` flag. If no selection is made and there are multiple `Main`
24-
modules, you will be asked to select from a list of options.
27+
module. You can specify which `Main` module to load with the
28+
`--main-is <target>` option. If no selection is made and there are multiple
29+
`Main` modules, you will be asked to select from a list of options.
2530

2631
## Speeding up initial load
2732

28-
There are two ways to speed up the initial startup of ghci:
33+
There are two ways to speed up the initial startup of GHCi:
2934

30-
* `--no-build`, to skip an initial build step. This only works if the
31-
dependencies have already been built.
35+
1. Pass the `--no-build` flag, to skip an initial build step. This works only
36+
if the dependencies have already been built.
3237

33-
* `--no-load`, to skip loading all defined modules into ghci. You can then
34-
directly use `:load MyModule` to load a specific module in your project.
38+
2. Pass the `--no-load` flag, to skip loading all defined modules into GHCi.
39+
You can then directly use `:load MyModule` in GHCi to load a specific module
40+
in your project.
3541

3642
## Loading just the main module
3743

3844
By default, `stack ghci` loads and imports all of the modules in the package.
39-
This allows you to easily use anything exported by your package. This is
40-
usually quite convenient, but in some cases it makes sense to only load one
41-
module, or no modules at all. The `--only-main` flag allows this. It specifies
42-
that only the main module will be loaded, if any. This is particularly useful
43-
in the following circumstances:
44-
45-
1. You're loading the project in order to run it in ghci (e.g. via `main`), and
46-
you intend to reload while developing. Without the `--only-main` flag, you
47-
will need to quit and restart ghci whenever a module gets deleted. With the
45+
This allows you to easily use anything exported by your package. This is usually
46+
quite convenient, but in some cases it makes sense to only load one module, or
47+
no modules at all. The `--only-main` flag allows this. It specifies that only
48+
the main module will be loaded, if any. This is particularly useful in the
49+
following circumstances:
50+
51+
1. You're loading the project in order to run it in GHCi (e.g. via `main`), and
52+
you intend to reload while developing. Without the `--only-main` flag, you
53+
will need to quit and restart GHCi whenever a module gets deleted. With the
4854
flag, reloading should work fine in this case.
4955

50-
2. If many of your modules have exports named the same thing, then you'll need to
51-
refer to them using qualified names. To avoid this, it may be easier to use
52-
`--only-main` to start with a blank slate and just import the modules you are
53-
interested in.
56+
2. If many of your modules have exports named the same thing, then you'll need
57+
to refer to them using qualified names. To avoid this, it may be easier to
58+
use the `--only-main` flag to start with a blank slate and just import the
59+
modules you are interested in.
5460

5561
## Loading a filepath directly
5662

57-
Instead of the `TARGET` syntax, it is also possible to directly run
58-
`stack ghci src/MyFile.hs`. This will figure out which component the file is
59-
associated with, and use the options from that component.
63+
Instead of the `TARGET` syntax, it is also possible to command directly, for
64+
example:
6065

61-
## Specifying extra packages to build / depend on
66+
~~~text
67+
stack ghci src/MyFile.hs
68+
~~~
6269

63-
Sometimes you want to load ghci with an additional package, that isn't a direct
64-
dependency of your components. This can be achieved by using the `--package` flag.
65-
For example, if I want to experiment with the lens library, I can run
66-
`stack ghci --package lens`.
70+
This will figure out which component the file is associated with, and use the
71+
options from that component.
6772

68-
## Running plain ghci
73+
## Specifying extra packages to build or depend on
6974

70-
`stack ghci` always runs ghci configured to load code from packages in your
71-
project. In particular, this means it passes in flags like `-hide-all-packages`
72-
and `-package-id=` in order to configure which packages are visible to ghci.
75+
Sometimes you want to load GHCi with an additional package, that isn't a direct
76+
dependency of your components. This can be achieved by using the `--package`
77+
option. For example, if I want to experiment with the `lens` library, I can
78+
command:
79+
80+
~~~text
81+
stack ghci --package lens
82+
~~~
83+
84+
## Running plain GHCi
85+
86+
`stack ghci` always runs GHCi configured to load code from packages in your
87+
project. In particular, this means it passes in flags like `-hide-all-packages`
88+
and `-package-id=` in order to configure which packages are visible to GHCi.
7389

7490
For doing experiments which just involve packages installed in your databases,
75-
it may be useful to run ghci plainly like `stack exec ghci`. This will run a
76-
plain `ghci` in an environment which includes `GHC_PACKAGE_PATH`, and so will
77-
have access to your databases.
78-
79-
*Note*: Running `stack ghci` on a pristine copy of the code doesn't currently
80-
build libraries
81-
([#2790](https://github.com/commercialhaskell/stack/issues/2790)) or internal
82-
libraries ([#4148](https://github.com/commercialhaskell/stack/issues/4148)).
83-
It is recommended to always run a `stack build` before running `stack ghci`,
84-
until these two issues are closed.
91+
it may be useful to run GHCi plainly like:
92+
93+
~~~text
94+
stack exec ghci
95+
~~~
96+
97+
This will run a plain GHCi in an environment which includes `GHC_PACKAGE_PATH`,
98+
and so will have access to your databases.
99+
100+
!!! note
101+
102+
Running `stack ghci` on a pristine copy of the code doesn't currently build
103+
libraries
104+
(issue [#2790](https://github.com/commercialhaskell/stack/issues/2790)) or
105+
internal libraries
106+
(issue [#4148](https://github.com/commercialhaskell/stack/issues/4148)). It
107+
is recommended to always use `stack build` before using `stack ghci`, until
108+
these two issues are closed.

doc/ghcjs.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ nav:
3535
- stack.yaml vs a Cabal file: stack_yaml_vs_cabal_package_file.md
3636
- Build command: build_command.md
3737
- Code coverage: coverage.md
38-
- Stack and Visual Studio Code: Stack_and_VS_Code.md
39-
- Developing on Windows: developing_on_windows.md
38+
- REPL environment: ghci.md
4039
- Dependency visualization: dependency_visualization.md
4140
- Docker integration: docker_integration.md
4241
- Nix integration: nix_integration.md
4342
- Non-standard project initialization: nonstandard_project_init.md
43+
- Stack and Visual Studio Code: Stack_and_VS_Code.md
44+
- Developing on Windows: developing_on_windows.md
4445
- Shell auto-completion: shell_autocompletion.md
4546
- Travis CI: travis_ci.md
4647
- Azure CI: azure_ci.md
47-
- GHCi: ghci.md
4848
- Lock files: lock_files.md
4949
- Advanced documentation:
5050
- Build overview: build_overview.md

0 commit comments

Comments
 (0)