<div dir="ltr">If I'm understanding correctly, I can follow the stack way of setting up a project in a directory, then if I start a ghci REPL in that directory, I'm in that project's sandbox, true? But if I start a ghci REPL in some directory that has no stack project already set up, then that REPL is relying on the global "project," so to speak. It's somewhat confusing since the project way of doing Haskell is to compile with ghc, and run at a shell (same as C) and not have a running ghci. Two different cultures. After working in the REPL-based world of, say, Scheme and Emacs Lisp, it's hard to come back to a code-compile-run world. In Emacs, all Lisp coding you do is feeding, tweaking a live Emacs beast. It's difficult for me as a Haskell beginner to understand why beginner tutorials all have me working with the ghci REPL -- but then that's apparently not how real-world Haskell works. Or is it? So Emacs is a running ball of C and Elisp code with an Elisp REPL that gives you control over the running system. Something similar is going on with, say, XMonad, right? XMonad is a running Haskell executable, but then you change XMonad by altering xmonad.hs and, I'm guessing, recompile the whole XMonad system, then restart it?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 7, 2021 at 6:45 PM Travis Cardwell <<a href="mailto:travis.cardwell@extrema.is">travis.cardwell@extrema.is</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Sorry to hear that it is still not working for you yet.<br>
<br>
On Tue, Jun 8, 2021 at 6:22 AM Galaxy Being wrote:<br>
> I installed stack on my Windows computer using chocolatey, which went<br>
> smoothly. But I had nothing anywhere I could find. On a hunch, at the<br>
> prompt I tried to run stack ghci, then it started downloading and<br>
> installing stuff. Good. I then was able to track down an example of a<br>
> stack.yaml in the ...stack/global-project directory. My whole<br>
> motivation was to see an actual global stack.yaml in the wild, and not<br>
> have to guess-and-test from the stack docs.<br>
<br>
Stack provides functionality to initialize a project with a "template"<br>
so that you do not have to start from scratch.  For example, if you want<br>
to start a new project called "HaskellTest" in your `~/Dropbox/org`<br>
directory, run the following commands:<br>
<br>
    $ cd ~/Dropbox/org<br>
    $ stack new HaskellTest<br>
<br>
The default template provides you with a `stack.yaml` file that includes<br>
documentation and examples.  The template also provides you with a<br>
`package.yaml` file (used to generate the `.cabal` file using hpack)<br>
that has a library, executable, and test suite configured, as well as<br>
stub source code and various other files.<br>
<br>
Note that in cases where you already have a Haskell project (with a<br>
`.cabal` or `package.yaml` file), the `stack init` command can be used<br>
to add just the `stack.yaml` to the existing project.<br>
<br>
> Good. I duplicated<br>
><br>
> packages: []<br>
> resolver: lts-17.15<br>
><br>
> on my Ubuntu 21.04 in the .stack/global-project/stack.yaml.<br>
<br>
Note that this `stack.yaml` file is for the "global-project" as it does<br>
not have any packages configured.  The `stack.yaml` file for any (other)<br>
project should list at least one package.<br>
<br>
> Tried running stack ghci from the Ubuntu prompt, and, similarly, it<br>
> started installing lots of stuff. (The resolver version I replaced was<br>
> lts-17.08. Why that old I don't know.).<br>
<br>
The resolver snapshot in the "global-project" is set when you first run<br>
Stack.  After that, it is up to you to update it *if/when* you would<br>
like to use a different snapshot.<br>
<br>
Similarly, the resolver snapshot for a project `stack.yaml` is set when<br>
you run `stack new` or `stack init`, and then it is up to you to<br>
maintain it as desired.<br>
<br>
> But then I got a cryptic error as it seemed to clash or not like<br>
> something it saw in some obscure github directory I had cloned ages<br>
> ago with Haskell example code. I deleted everything in the github<br>
> directory that looked stack/cabal-ish and tried stack ghci again. Now<br>
> it says<br>
><br>
> Warning (added by new or init): Some packages were found to have names conflicting with others and have been commented out in the packages section.<br>
> Warning (added by new or init): Some packages were found to be incompatible with the resolver and have been left commented out in the packages section.<br>
> You can omit this message by removing it from stack.yaml<br>
><br>
> Stack looks for packages in the directories configured in<br>
> the 'packages' and 'extra-deps' fields defined in your stack.yaml<br>
> The current entry points to /home/galaxybeing/Dropbox/org/HaskellRoad/,<br>
> but no .cabal or package.yaml file could be found there.<br>
><br>
> Yes, that was the directory I purged. My<br>
> .stack/global-project/stack.yaml contains only<br>
><br>
> packages: []<br>
> resolver: lts-17.15<br>
<br>
These errors indicate that `~/.stack/global-project/stack.yaml` is *not*<br>
being used.  It is likely that you are running `stack` commands in a<br>
directory that contains a `stack.yaml` file which references these other<br>
directories, and that file is being used.  Try (re)moving that<br>
`stack.yaml` file and trying again.  Do the errors persist?<br>
<br>
Once you (re)move the project `stack.yaml` configuration, the<br>
`stack ghci` will use the `~/.stack/global-project/stack.yaml`<br>
configuration.  With the above content, the LTS 17.15 resolver will be<br>
used, with no packages configured.  As explained in my previous email,<br>
this does *not* expose libraries to GHCi.  If you want to expose<br>
libraries in the global project, you need to follow the instructions I<br>
gave previously for configuring the global project.<br>
<br>
> Not sure how to proceed. Seeing how that vast majority of Haskell<br>
> intro books don't use projects, just install, start ghci, load code at<br>
> the REPL prompt, I'd really like to nail this "global", non-project<br>
> stack down.<br>
<br>
Indeed.  Installation is tricky, particularly across multiple operating<br>
systems.  Most book authors avoid writing about it, as writing about it<br>
in sufficient detail would likely fill a book itself.  Most beginner<br>
books even stick with the `base` package so that readers do not even<br>
have to worry about packages.<br>
<br>
Global installation of packages leads to a *lot* of trouble when you get<br>
to more complex development.  When I first learned Haskell, I would<br>
occasionally completely remove my package database when I got into a<br>
situation that was difficult to resolve.  The situation improved a lot<br>
when Cabal introduced sandbox features, allowing dependencies to be<br>
managed separately per project.  Stack is project-based for the same<br>
reason: allowing each project to use separate sets of packages makes<br>
things a lot easier.  The "global-project" is called "global" because<br>
it is used when outside of any other Haskell project (determined by the<br>
existence of a `stack.yaml` file in the current working directory), but<br>
note that it is actually a project.  Following the instructions that I<br>
wrote in my previous email, you can configure Stack to work in the way<br>
that you want *without* running into the aforementioned trouble even<br>
when you start to develop other projects.<br>
<br>
Good luck!<br>
<br>
Travis<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>⨽<br></div>Lawrence Bottorff<div>Grand Marais, MN, USA</div><div><a href="mailto:borgauf@gmail.com" target="_blank">borgauf@gmail.com</a></div></div></div>