Installing a Stack Project
Finally, once we are satisfied that our program works as intended, we usually do
not want to run it using stack run
. After all, the point of Haskell being a
compiled language is that we can compile our Haskell code and then run the
program without even having Stack or GHC installed on our computer. In order to
be able to run our program without using stack
, we need to install it. The
command to do this is
$ stack install
Copying from /Users/nzeh/Documents/Teaching/Courses/3137/hello-world/.stack-work/install/aarch64-osx/30665e6a8eb3dd4cf3caecaaed8af8f238959b36768fc4cd801124b81c392c48/9.2.7/bin/hello-world-exe to /Users/nzeh/.local/bin/hello-world-exe
Copied executables to /Users/nzeh/.local/bin:
- hello-world-exe
This says that hello-world-exe
was installed to the folder .local/bin
in my
home directory. If .local/bin
is in my shell's path, then I can run the
program in the same way as I can run any other program on my computer:
$ hello-world-exe
someFunc
Once again, stack install
first compiles our project before installing it if
any of the source code files have changed since the last stack build
,
stack run
or stack install
command.
Note that if our program takes command line arguments, we can pass them to our program normally now, without the need to use two dashes before the list of arguments:
$ hello-world-exe <arguments to be passed to the program>
The double dashes when running the program using stack run
are necessary only
because entering stack run
at the shell prompt (obviously) doesn't run our
program directly. It runs stack
with run
as its first argument. stack
recognizes run
as an instruction to run our program. It then reads the list of
command line options that follow. It treats them as options to configure stack
itself until it sees two dashes. It then runs our program and passes the
arguments that follow the two dashes to our program.