You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once a version of GHC and, on Windows, a version of MSYS2, is installed, Stack
109
+
will then build your project. The end of the output should look similar to this:
84
110
85
-
GHC will be installed to your Stack programs directory, so calling `ghc` on
86
-
the command line won't work. See the `stack exec`, `stack ghc`, and
87
-
`stack runghc` commands below for more information.
111
+
=== "Unix-like"
112
+
113
+
~~~text
114
+
...
115
+
helloworld> configure (lib + exe)
116
+
Configuring helloworld-0.1.0.0...
117
+
helloworld> build (lib + exe) with ghc-9.6.6
118
+
Preprocessing library for helloworld-0.1.0.0..
119
+
Building library for helloworld-0.1.0.0..
120
+
[1 of 2] Compiling Lib
121
+
[2 of 2] Compiling Paths_helloworld
122
+
Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0..
123
+
Building executable 'helloworld-exe' for helloworld-0.1.0.0..
124
+
[1 of 2] Compiling Main
125
+
[2 of 2] Compiling Paths_helloworld
126
+
[3 of 3] Linking .stack-work/dist/x86_64-linux-tinfo6/ghc-9.6.6/build/helloworld-exe/helloworld-exe
127
+
helloworld> copy/register
128
+
Installing library in .../helloworld/.stack-work/install/x86_64-linux-tinfo6/a2caceceda039eb4f791856f85a68f9582d4daf3d0527344693ff3d1fcd92ba4/9.6.6/lib/x86_64-linux-ghc-9.6.6/helloworld-0.1.0.0-KFyX8zLxDvzLZURq3JaCVX
129
+
Installing executable helloworld-exe in .../helloworld/.stack-work/install/x86_64-linux-tinfo6/a2caceceda039eb4f791856f85a68f9582d4daf3d0527344693ff3d1fcd92ba4/9.6.6/bin
130
+
Registering library for helloworld-0.1.0.0..
131
+
~~~
88
132
89
-
Once a version of GHC is installed, Stack will then build your project.
133
+
=== "Windows"
134
+
135
+
~~~text
136
+
...
137
+
helloworld> configure (lib + exe)
138
+
Configuring helloworld-0.1.0.0...
139
+
helloworld> build (lib + exe) with ghc-9.6.6
140
+
Preprocessing library for helloworld-0.1.0.0..
141
+
Building library for helloworld-0.1.0.0..
142
+
[1 of 2] Compiling Lib
143
+
[2 of 2] Compiling Paths_helloworld
144
+
Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0..
145
+
Building executable 'helloworld-exe' for helloworld-0.1.0.0..
146
+
[1 of 2] Compiling Main
147
+
[2 of 2] Compiling Paths_helloworld
148
+
[3 of 3] Linking .stack-work\dist\effaccc7\build\helloworld-exe\helloworld-exe.exe
149
+
helloworld> copy/register
150
+
Installing library in ...\helloworld\.stack-work\install\c8c71a24\lib\x86_64-windows-ghc-9.6.6\helloworld-0.1.0.0-KFyX8zLxDvzLZURq3JaCVX
151
+
Installing executable helloworld-exe in ...\helloworld\.stack-work\install\c8c71a24\bin
152
+
Registering library for helloworld-0.1.0.0..
153
+
~~~
154
+
155
+
On Windows, Stack uses hashes of certain information to keep paths short.
90
156
91
157
## The `stack exec` command
92
158
@@ -96,14 +162,44 @@ Windows, `helloworld-exe.exe`). We'll explain more in the next section, but, for
96
162
now, just notice that the executables are installed in a location in our
97
163
project's `.stack-work` directory.
98
164
99
-
Now, Let's use the `stack exec` command to run our executable (which just
100
-
outputs "someFunc"):
165
+
Now, let's use the [`stack exec`](../commands/exec_command.md) command to run
166
+
our executable. We command:
101
167
102
168
~~~text
103
169
stack exec helloworld-exe
170
+
~~~
171
+
172
+
and the output is just:
173
+
~~~text
104
174
someFunc
105
175
~~~
106
176
177
+
??? question "Why is the output just `someFunc`?"
178
+
179
+
The code in the `new-template` project template is very simple. The package
180
+
has a Haskell module `Lib`:
181
+
~~~haskell
182
+
module Lib
183
+
( someFunc
184
+
) where
185
+
186
+
someFunc :: IO ()
187
+
someFunc = putStrLn "someFunc"
188
+
~~~
189
+
190
+
and a Haskell module `Main`:
191
+
~~~haskell
192
+
module Main (main) where
193
+
194
+
import Lib
195
+
196
+
main :: IO ()
197
+
main = someFunc
198
+
~~~
199
+
200
+
`putStrLn "someFunc"` is an action that, when executed, outputs the string
201
+
`someFunc` to the standard output channel.
202
+
107
203
`stack exec` works by providing the same reproducible environment that was used
108
204
to build your project to the command that you are running. Thus, it knew where
109
205
to find `helloworld-exe` even though it is hidden in the `.stack-work`
0 commit comments