How to install Haskell (Platform or Stack) in 2018 on Linux?












13















I am trying to learn Haskell from the book Learn You a Haskell by Miran Lipovača. Both the book and haskell.org recommends installing the Haskell Platform but there is no download for Manjaro Linux (Arch based) which I use.



I found this guide from 2014 and decided to install the packages from Manjaro's repository. This worked fine until I wanted to use haskell-mode in Emacs. I troubleshooted this and found out that it was a problem with the packages (Stack mainly).



Looking for ways to fix this I found this Reddit thread, which describes ways to install Haskell (not the Platform), and problems with the packages. I followed one of the comments and ended up installing Stack (and GHC) with the script as described here:



wget -qO- https://get.haskellstack.org/ | sh
stack setup
stack update


My questions are related to this:




  1. Is this the recommended starter way to install a functioning Haskell (Platform) on Linux (Manjaro) in 2018? If not: what is the/a way to do it?

  2. Haskell Platform contains: GHC, Cabal, Stack, and some packages. GHC and Stack are installed, how do I install Cabal through Stack?

  3. Do I need Cabal (Stack seems to have overlapping functionality)?

  4. Looking at the packages of the Haskell Platform, what, if anything, am I missing by installing Stack as described above? Looking in $HOME/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.2.2/lib/ghc-8.2.2 many of these seems installed already.










share|improve this question





























    13















    I am trying to learn Haskell from the book Learn You a Haskell by Miran Lipovača. Both the book and haskell.org recommends installing the Haskell Platform but there is no download for Manjaro Linux (Arch based) which I use.



    I found this guide from 2014 and decided to install the packages from Manjaro's repository. This worked fine until I wanted to use haskell-mode in Emacs. I troubleshooted this and found out that it was a problem with the packages (Stack mainly).



    Looking for ways to fix this I found this Reddit thread, which describes ways to install Haskell (not the Platform), and problems with the packages. I followed one of the comments and ended up installing Stack (and GHC) with the script as described here:



    wget -qO- https://get.haskellstack.org/ | sh
    stack setup
    stack update


    My questions are related to this:




    1. Is this the recommended starter way to install a functioning Haskell (Platform) on Linux (Manjaro) in 2018? If not: what is the/a way to do it?

    2. Haskell Platform contains: GHC, Cabal, Stack, and some packages. GHC and Stack are installed, how do I install Cabal through Stack?

    3. Do I need Cabal (Stack seems to have overlapping functionality)?

    4. Looking at the packages of the Haskell Platform, what, if anything, am I missing by installing Stack as described above? Looking in $HOME/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.2.2/lib/ghc-8.2.2 many of these seems installed already.










    share|improve this question



























      13












      13








      13


      8






      I am trying to learn Haskell from the book Learn You a Haskell by Miran Lipovača. Both the book and haskell.org recommends installing the Haskell Platform but there is no download for Manjaro Linux (Arch based) which I use.



      I found this guide from 2014 and decided to install the packages from Manjaro's repository. This worked fine until I wanted to use haskell-mode in Emacs. I troubleshooted this and found out that it was a problem with the packages (Stack mainly).



      Looking for ways to fix this I found this Reddit thread, which describes ways to install Haskell (not the Platform), and problems with the packages. I followed one of the comments and ended up installing Stack (and GHC) with the script as described here:



      wget -qO- https://get.haskellstack.org/ | sh
      stack setup
      stack update


      My questions are related to this:




      1. Is this the recommended starter way to install a functioning Haskell (Platform) on Linux (Manjaro) in 2018? If not: what is the/a way to do it?

      2. Haskell Platform contains: GHC, Cabal, Stack, and some packages. GHC and Stack are installed, how do I install Cabal through Stack?

      3. Do I need Cabal (Stack seems to have overlapping functionality)?

      4. Looking at the packages of the Haskell Platform, what, if anything, am I missing by installing Stack as described above? Looking in $HOME/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.2.2/lib/ghc-8.2.2 many of these seems installed already.










      share|improve this question
















      I am trying to learn Haskell from the book Learn You a Haskell by Miran Lipovača. Both the book and haskell.org recommends installing the Haskell Platform but there is no download for Manjaro Linux (Arch based) which I use.



      I found this guide from 2014 and decided to install the packages from Manjaro's repository. This worked fine until I wanted to use haskell-mode in Emacs. I troubleshooted this and found out that it was a problem with the packages (Stack mainly).



      Looking for ways to fix this I found this Reddit thread, which describes ways to install Haskell (not the Platform), and problems with the packages. I followed one of the comments and ended up installing Stack (and GHC) with the script as described here:



      wget -qO- https://get.haskellstack.org/ | sh
      stack setup
      stack update


      My questions are related to this:




      1. Is this the recommended starter way to install a functioning Haskell (Platform) on Linux (Manjaro) in 2018? If not: what is the/a way to do it?

      2. Haskell Platform contains: GHC, Cabal, Stack, and some packages. GHC and Stack are installed, how do I install Cabal through Stack?

      3. Do I need Cabal (Stack seems to have overlapping functionality)?

      4. Looking at the packages of the Haskell Platform, what, if anything, am I missing by installing Stack as described above? Looking in $HOME/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.2.2/lib/ghc-8.2.2 many of these seems installed already.







      linux haskell cabal haskell-stack haskell-platform






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 12 '18 at 1:50









      duplode

      23.2k44987




      23.2k44987










      asked Feb 11 '18 at 16:54









      KloraxKlorax

      214138




      214138
























          2 Answers
          2






          active

          oldest

          votes


















          25














          Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.



          TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).



          Here's the long answer...



          Stack vs. Platform vs. Cabal



          The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).



          Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.



          Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):





          $ stack install cabal-install


          But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:



          $ stack exec --no-ghc-package-path cabal -- list


          and it doesn't really do anything useful as far as your Stack environment is concerned.



          Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.



          What's Missing with Stack



          I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:



          $ echo 'main = putStrLn "Hello, world!"' > Hello.hs
          $ stack ghc -- Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o )
          Linking Hello ...
          $ ./Hello
          Hello, world!
          $


          or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:



          $ stack exec bash
          $ ghci
          GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
          Prelude> :quit
          $ ghc -O2 Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o ) [flags changed]
          Linking Hello ...
          $ exit
          $ ghc
          The program 'ghc' is currently not installed. ...
          $


          The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:



          $ stack install random


          and restart your interpreter.



          Recommendation to Use Haskell Platform



          Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.



          In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.



          Beginner Workflow for a Pure Stack Installation



          If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:



          You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):



          $ cd
          $ stack path --project-root
          /u/buhr/.stack/global-project
          $


          When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:



          $ stack exec ghci
          $ stack ghc -- -O2 Hello.hs


          and they will both have access to any additional libraries (packages) you've installed using commands like:



          $ stack install random


          Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.



          Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.



          You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)



          Configuring Haskell-Mode (for Either Platform or Stack)



          It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:



          (require 'haskell)

          ;; add capability to submit code to interpreter and mark errors
          (add-hook 'haskell-mode-hook 'interactive-haskell-mode)

          ;; add missing keybindings for navigating errors
          (define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
          (define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
          (define-key interactive-haskell-mode-map (kbd "C-c M-p")
          'haskell-goto-first-error)

          ;; merge this with your existing custom-set-variables
          (custom-set-variables

          ;; NOTE: include following line to work around haskell-mode
          ;; bug if using GHC >= 8.2.1.
          ;; See: https://github.com/haskell/haskell-mode/issues/1553
          '(haskell-process-args-stack-ghci
          '("--ghci-options=-ferror-spans -fshow-loaded-modules"
          "--no-build" "--no-load"))

          ;; some options suggested in the haskell-mode documentation
          '(haskell-process-auto-import-loaded-modules t)
          '(haskell-process-log t)
          '(haskell-process-suggest-remove-import-lines t)

          ;; make sure "stack ghci" is used, even in the global project
          '(haskell-process-type 'stack-ghci))


          I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)



          If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)



          Hope that helps!






          share|improve this answer


























          • I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

            – K. A. Buhr
            Feb 11 '18 at 22:53



















          5














          You have three choices.



          Haskell Platform



          It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.



          Stack



          This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.



          Nix



          This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.



          I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.






          share|improve this answer



















          • 3





            My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

            – Carl
            Feb 11 '18 at 21:12











          • @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

            – user2847643
            Feb 11 '18 at 21:42











          • @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

            – sclv
            Feb 14 '18 at 5:57












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48733970%2fhow-to-install-haskell-platform-or-stack-in-2018-on-linux%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          25














          Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.



          TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).



          Here's the long answer...



          Stack vs. Platform vs. Cabal



          The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).



          Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.



          Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):





          $ stack install cabal-install


          But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:



          $ stack exec --no-ghc-package-path cabal -- list


          and it doesn't really do anything useful as far as your Stack environment is concerned.



          Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.



          What's Missing with Stack



          I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:



          $ echo 'main = putStrLn "Hello, world!"' > Hello.hs
          $ stack ghc -- Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o )
          Linking Hello ...
          $ ./Hello
          Hello, world!
          $


          or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:



          $ stack exec bash
          $ ghci
          GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
          Prelude> :quit
          $ ghc -O2 Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o ) [flags changed]
          Linking Hello ...
          $ exit
          $ ghc
          The program 'ghc' is currently not installed. ...
          $


          The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:



          $ stack install random


          and restart your interpreter.



          Recommendation to Use Haskell Platform



          Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.



          In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.



          Beginner Workflow for a Pure Stack Installation



          If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:



          You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):



          $ cd
          $ stack path --project-root
          /u/buhr/.stack/global-project
          $


          When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:



          $ stack exec ghci
          $ stack ghc -- -O2 Hello.hs


          and they will both have access to any additional libraries (packages) you've installed using commands like:



          $ stack install random


          Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.



          Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.



          You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)



          Configuring Haskell-Mode (for Either Platform or Stack)



          It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:



          (require 'haskell)

          ;; add capability to submit code to interpreter and mark errors
          (add-hook 'haskell-mode-hook 'interactive-haskell-mode)

          ;; add missing keybindings for navigating errors
          (define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
          (define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
          (define-key interactive-haskell-mode-map (kbd "C-c M-p")
          'haskell-goto-first-error)

          ;; merge this with your existing custom-set-variables
          (custom-set-variables

          ;; NOTE: include following line to work around haskell-mode
          ;; bug if using GHC >= 8.2.1.
          ;; See: https://github.com/haskell/haskell-mode/issues/1553
          '(haskell-process-args-stack-ghci
          '("--ghci-options=-ferror-spans -fshow-loaded-modules"
          "--no-build" "--no-load"))

          ;; some options suggested in the haskell-mode documentation
          '(haskell-process-auto-import-loaded-modules t)
          '(haskell-process-log t)
          '(haskell-process-suggest-remove-import-lines t)

          ;; make sure "stack ghci" is used, even in the global project
          '(haskell-process-type 'stack-ghci))


          I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)



          If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)



          Hope that helps!






          share|improve this answer


























          • I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

            – K. A. Buhr
            Feb 11 '18 at 22:53
















          25














          Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.



          TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).



          Here's the long answer...



          Stack vs. Platform vs. Cabal



          The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).



          Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.



          Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):





          $ stack install cabal-install


          But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:



          $ stack exec --no-ghc-package-path cabal -- list


          and it doesn't really do anything useful as far as your Stack environment is concerned.



          Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.



          What's Missing with Stack



          I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:



          $ echo 'main = putStrLn "Hello, world!"' > Hello.hs
          $ stack ghc -- Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o )
          Linking Hello ...
          $ ./Hello
          Hello, world!
          $


          or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:



          $ stack exec bash
          $ ghci
          GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
          Prelude> :quit
          $ ghc -O2 Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o ) [flags changed]
          Linking Hello ...
          $ exit
          $ ghc
          The program 'ghc' is currently not installed. ...
          $


          The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:



          $ stack install random


          and restart your interpreter.



          Recommendation to Use Haskell Platform



          Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.



          In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.



          Beginner Workflow for a Pure Stack Installation



          If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:



          You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):



          $ cd
          $ stack path --project-root
          /u/buhr/.stack/global-project
          $


          When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:



          $ stack exec ghci
          $ stack ghc -- -O2 Hello.hs


          and they will both have access to any additional libraries (packages) you've installed using commands like:



          $ stack install random


          Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.



          Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.



          You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)



          Configuring Haskell-Mode (for Either Platform or Stack)



          It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:



          (require 'haskell)

          ;; add capability to submit code to interpreter and mark errors
          (add-hook 'haskell-mode-hook 'interactive-haskell-mode)

          ;; add missing keybindings for navigating errors
          (define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
          (define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
          (define-key interactive-haskell-mode-map (kbd "C-c M-p")
          'haskell-goto-first-error)

          ;; merge this with your existing custom-set-variables
          (custom-set-variables

          ;; NOTE: include following line to work around haskell-mode
          ;; bug if using GHC >= 8.2.1.
          ;; See: https://github.com/haskell/haskell-mode/issues/1553
          '(haskell-process-args-stack-ghci
          '("--ghci-options=-ferror-spans -fshow-loaded-modules"
          "--no-build" "--no-load"))

          ;; some options suggested in the haskell-mode documentation
          '(haskell-process-auto-import-loaded-modules t)
          '(haskell-process-log t)
          '(haskell-process-suggest-remove-import-lines t)

          ;; make sure "stack ghci" is used, even in the global project
          '(haskell-process-type 'stack-ghci))


          I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)



          If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)



          Hope that helps!






          share|improve this answer


























          • I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

            – K. A. Buhr
            Feb 11 '18 at 22:53














          25












          25








          25







          Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.



          TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).



          Here's the long answer...



          Stack vs. Platform vs. Cabal



          The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).



          Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.



          Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):





          $ stack install cabal-install


          But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:



          $ stack exec --no-ghc-package-path cabal -- list


          and it doesn't really do anything useful as far as your Stack environment is concerned.



          Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.



          What's Missing with Stack



          I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:



          $ echo 'main = putStrLn "Hello, world!"' > Hello.hs
          $ stack ghc -- Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o )
          Linking Hello ...
          $ ./Hello
          Hello, world!
          $


          or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:



          $ stack exec bash
          $ ghci
          GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
          Prelude> :quit
          $ ghc -O2 Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o ) [flags changed]
          Linking Hello ...
          $ exit
          $ ghc
          The program 'ghc' is currently not installed. ...
          $


          The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:



          $ stack install random


          and restart your interpreter.



          Recommendation to Use Haskell Platform



          Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.



          In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.



          Beginner Workflow for a Pure Stack Installation



          If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:



          You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):



          $ cd
          $ stack path --project-root
          /u/buhr/.stack/global-project
          $


          When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:



          $ stack exec ghci
          $ stack ghc -- -O2 Hello.hs


          and they will both have access to any additional libraries (packages) you've installed using commands like:



          $ stack install random


          Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.



          Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.



          You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)



          Configuring Haskell-Mode (for Either Platform or Stack)



          It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:



          (require 'haskell)

          ;; add capability to submit code to interpreter and mark errors
          (add-hook 'haskell-mode-hook 'interactive-haskell-mode)

          ;; add missing keybindings for navigating errors
          (define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
          (define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
          (define-key interactive-haskell-mode-map (kbd "C-c M-p")
          'haskell-goto-first-error)

          ;; merge this with your existing custom-set-variables
          (custom-set-variables

          ;; NOTE: include following line to work around haskell-mode
          ;; bug if using GHC >= 8.2.1.
          ;; See: https://github.com/haskell/haskell-mode/issues/1553
          '(haskell-process-args-stack-ghci
          '("--ghci-options=-ferror-spans -fshow-loaded-modules"
          "--no-build" "--no-load"))

          ;; some options suggested in the haskell-mode documentation
          '(haskell-process-auto-import-loaded-modules t)
          '(haskell-process-log t)
          '(haskell-process-suggest-remove-import-lines t)

          ;; make sure "stack ghci" is used, even in the global project
          '(haskell-process-type 'stack-ghci))


          I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)



          If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)



          Hope that helps!






          share|improve this answer















          Here's a (long) alternative answer. Note that I used to recommend Stack for beginners, too, but I've since changed my mind.



          TL;DR: Either Haskell Platform or a pure Stack installation can provide you with everything you need, and you won't be "missing" anything by choosing one or the other. You'll probably find it easiest to skip Stack and install Haskell Platform using the "Generic" Linux installer, because it comes with everything you need and the setup will more closely matched what's described in the LYAH book. You can install Stack later when you're doing more serious development on multiple projects. If you prefer to stick with a pure Stack installation, I'd suggest starting with a "global project only" workflow. Either way, you can use "haskell-mode" with some configuration fixes suggested below (including a key setting that will be required if you're working in the global project of a Stack-only installation).



          Here's the long answer...



          Stack vs. Platform vs. Cabal



          The LYAH book pre-dates Stack, which is certainly the main reason it doesn't mention it. At haskell.org, they recommend using either a minimal installer, Stack, or the Haskell Platform. All three methods are perfectly reasonable ways in 2018 to set up a working Haskell environment. They differ both in the ways they choose to isolate different versions of the compiler and/or libraries into "sandboxes" for development work, and in how much they install initially, but there's nothing "missing" from any one of them that can't be installed on demand. Depending on which you choose, there will be some differences in your workflow (see below).



          Both Stack and Cabal are combined package managers and build tools. (Stack has the added ability to actually bootstrap an entire Haskell installation, which is why it's also an installation method in its own right.) While you're working through LYAH, you won't actually be using the "build tool" functionality directly on your own projects. (The built-in build facilities of GHC are more than adequate for building small, multi-module projects.) You'll just need the package manager functionality to install additional libraries.



          Since Stack and Cabal manage their packages separately, if you're using Stack, you'll have no particular need to use Cabal directly. You can install it if you want (and in fact, Stack makes use of Cabal for some esoteric functionality, like "stack solver", and will require it to be installed in those cases):





          $ stack install cabal-install


          But, even though this will put "cabal" into "$HOME/.local/bin" (and you'll want to make sure this is in your path), you'll find that you need to jump through hoops to run it:



          $ stack exec --no-ghc-package-path cabal -- list


          and it doesn't really do anything useful as far as your Stack environment is concerned.



          Update: A note on the "$HOME/.local/bin" path. It looks like the installation script from https://get.haskellstack.org/ may install Stack itself to /usr/local/bin/stack by default if there's no existing installation. However, it should display a warning to put $HOME/.local/bin in your path. If you upgrade Stack in the future with stack upgrade, it'll install the new version of stack there, and that directory will also be used if you install packages that include binaries. For example, stack install hlint will install the Haskell Lint program hlint to that directory. So, it's a good idea to have it in your path and somewhere before /usr/local/bin.



          What's Missing with Stack



          I think that covers your first three questions. For your last, the main thing you're missing having installed Stack instead of the Haskell Platform is that, by design, Stack doesn't really install anything globally other than "stack" itself. So, all your Haskell work including running the Haskell interpreter ("ghci") or compiler ("ghc"), all needs to be done within a Stack environment, either using a specific corresponding Stack command:



          $ echo 'main = putStrLn "Hello, world!"' > Hello.hs
          $ stack ghc -- Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o )
          Linking Hello ...
          $ ./Hello
          Hello, world!
          $


          or else using "stack exec" to run a generic program within an appropriate Stack environment. For example, it can sometimes be helpful to run a Bash shell under stack, after which things behave sort of like a globally installed Haskell Platform environment:



          $ stack exec bash
          $ ghci
          GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
          Prelude> :quit
          $ ghc -O2 Hello.hs
          [1 of 1] Compiling Main ( Hello.hs, Hello.o ) [flags changed]
          Linking Hello ...
          $ exit
          $ ghc
          The program 'ghc' is currently not installed. ...
          $


          The other thing you're missing is that the Haskell Platform installs a whole bunch of common libraries by default, while a fresh Stack environment starts with almost nothing (not even the compiler, before you run stack setup). While working through LYAH, you may find you need to periodically install additional libraries. For example, in the Input and Output chapter, the examples using random numbers (module System.Random) will require you to run:



          $ stack install random


          and restart your interpreter.



          Recommendation to Use Haskell Platform



          Because Stack is a little complicated and you won't really need the facilities it provides at the beginning, you may find the Haskell Platform easier to use when you're starting out. (The "Generic" installer should work fine on your distribution.) It comes with everything installed, and the way you use it will more closely match the way things are described in LYAH. Together with haskell-mode, you should have a pretty decent Haskell environment.



          In general, there should be no issue having Stack and the Haskell Platform installed side-by-side (as evidenced by the fact that Haskell Platform actually includes Stack). Stack will maintain everything separately under the "$HOME/.stack" subdirectory, so there will be no interference between compilers or packages or anything. Note that in this setup, you'll use cabal to manage the packages installed on the Platform side of things, and stack -- obviously -- to manage packages on the Stack side.



          Beginner Workflow for a Pure Stack Installation



          If you want to stick with your pure Stack installation, I might suggest the following workflow when you're starting out:



          You will see references to Stack projects, created with "stack new" or "stack init". Avoid these at the beginning, and stick with the stack "global project". This is the implicit project that will be in effect when you run "stack" in a directory that doesn't have a "stack.yaml" file (directly or in a parent directory):



          $ cd
          $ stack path --project-root
          /u/buhr/.stack/global-project
          $


          When you're working in the global project (i.e., not somewhere under a stack.yaml file), you can invoke the interpreter and compiler with:



          $ stack exec ghci
          $ stack ghc -- -O2 Hello.hs


          and they will both have access to any additional libraries (packages) you've installed using commands like:



          $ stack install random


          Updated: A note on the difference between stack ghci and stack exec ghci. The former is intended to run GHCi within the context of a local project (i.e., working under a stack.yaml file). It passes some additional flags to hide globally installed packages and to automatically make available modules from your package. When working in the global project, I don't think there's any practical difference except that stack ghci generates a warning; and no matter which you use, you'll need to load your own modules explicitly with :load Whatever.hs. There's a little more info on the difference on this Stack documentation page, particularly at the bottom where it tries to explain the difference.



          Eventually, you may switch to a workflow that uses Stack projects. This will involve using stack new to create a new Stack project directory, stack setup to install/link a private compiler version into that directory, and then modifying the project's xxx.cabal file (and possibly its stack.yaml file) to indicate which additional packages are required, instead of using stack install. It's all a little complicated when you just want to get started writing code.



          You may also see reference to Intero, an Emacs mode designed specifically for Stack. Intero is very nice, but it doesn't work very well when working on files in the global project. It'll tend to want to start up the interpreter in the directory "~/.stack/global-project", which is pretty useless. (I use Intero, but I've patched it to behave better in this respect.)



          Configuring Haskell-Mode (for Either Platform or Stack)



          It's probably best to stick with "haskell-mode" instead, and think about Intero when you start using non-global projects. I'd suggest installing "haskell-mode" from MELPA as per the instructions, but adding the following to your .emacs file instead of what's suggested in the documentation:



          (require 'haskell)

          ;; add capability to submit code to interpreter and mark errors
          (add-hook 'haskell-mode-hook 'interactive-haskell-mode)

          ;; add missing keybindings for navigating errors
          (define-key interactive-haskell-mode-map (kbd "M-n") 'haskell-goto-next-error)
          (define-key interactive-haskell-mode-map (kbd "M-p") 'haskell-goto-prev-error)
          (define-key interactive-haskell-mode-map (kbd "C-c M-p")
          'haskell-goto-first-error)

          ;; merge this with your existing custom-set-variables
          (custom-set-variables

          ;; NOTE: include following line to work around haskell-mode
          ;; bug if using GHC >= 8.2.1.
          ;; See: https://github.com/haskell/haskell-mode/issues/1553
          '(haskell-process-args-stack-ghci
          '("--ghci-options=-ferror-spans -fshow-loaded-modules"
          "--no-build" "--no-load"))

          ;; some options suggested in the haskell-mode documentation
          '(haskell-process-auto-import-loaded-modules t)
          '(haskell-process-log t)
          '(haskell-process-suggest-remove-import-lines t)

          ;; make sure "stack ghci" is used, even in the global project
          '(haskell-process-type 'stack-ghci))


          I've tested this with a pure Stack installation using "haskell-mode-20171022.26", and it seems to work fine. I can load a new Haskell file in the global project, submit it to an interactive session with "C-c C-l", and browse highlighted errors in the source file with "M-n" and "M-p". (The errors appear in the mini-buffer.)



          If you decide to use the Haskell Platform instead, I think all of this "haskell-mode" configuration will still apply, except you should remove the very last customization line. (The default haskell-process-type of auto will pick something appropriate.)



          Hope that helps!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 21:55









          mkrieger1

          4,72922133




          4,72922133










          answered Feb 11 '18 at 21:18









          K. A. BuhrK. A. Buhr

          15.1k11537




          15.1k11537













          • I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

            – K. A. Buhr
            Feb 11 '18 at 22:53



















          • I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

            – K. A. Buhr
            Feb 11 '18 at 22:53

















          I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

          – K. A. Buhr
          Feb 11 '18 at 22:53





          I added notes (marked with Updated) to the answer to address your questions about the PATH and stack ghci. With respect to question 4, a brand new Stack installation includes the core platform packages (e.g., containers, which does seem to be available in the global project without further installation), but is missing most of the libraries available with the Full Platform (e.g., including some very popular ones like random, text, and mtl).

          – K. A. Buhr
          Feb 11 '18 at 22:53













          5














          You have three choices.



          Haskell Platform



          It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.



          Stack



          This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.



          Nix



          This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.



          I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.






          share|improve this answer



















          • 3





            My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

            – Carl
            Feb 11 '18 at 21:12











          • @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

            – user2847643
            Feb 11 '18 at 21:42











          • @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

            – sclv
            Feb 14 '18 at 5:57
















          5














          You have three choices.



          Haskell Platform



          It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.



          Stack



          This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.



          Nix



          This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.



          I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.






          share|improve this answer



















          • 3





            My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

            – Carl
            Feb 11 '18 at 21:12











          • @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

            – user2847643
            Feb 11 '18 at 21:42











          • @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

            – sclv
            Feb 14 '18 at 5:57














          5












          5








          5







          You have three choices.



          Haskell Platform



          It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.



          Stack



          This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.



          Nix



          This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.



          I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.






          share|improve this answer













          You have three choices.



          Haskell Platform



          It is a possibility but not a popular choice for many reasons which you will discover in due time if you choose to go this way. You will have a much better experience and get much better support with either Stack or Nix. Which of those two people use seems to be mostly about personal preference. They are different beasts but to a beginner the differences will not be immediately obvious so there's little hope that you will be able to make an "informed decision". Just pick one and reevaluate later.



          Stack



          This is what I would suggest to anyone (not familiar with Nix) wanting to get started with Haskell quickly. Period. You do not need to separately install anything, Stack will handle all the Haskell stuff for you. You don't normally ever use cabal directly with Stack. stack build uses cabal internally but you don't need to worry about that. One thing to note, Stack is not a package manager. It's a build tool. It doesn't normally install anything. It does however fetch all the dependencies that it needs and stores them in ~/.stack together with other things.



          Nix



          This is what I use personally so I may be biased but I think this is the best solution overall in the long term. The caveat is that there is a rather steep learning curve and you are given many chances to shoot yourself in the foot when starting out.



          I highly recommend starting with Stack but keeping an open mind about Nix as your journey with Haskell continues.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 11 '18 at 21:07









          user2847643user2847643

          2,5701021




          2,5701021








          • 3





            My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

            – Carl
            Feb 11 '18 at 21:12











          • @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

            – user2847643
            Feb 11 '18 at 21:42











          • @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

            – sclv
            Feb 14 '18 at 5:57














          • 3





            My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

            – Carl
            Feb 11 '18 at 21:12











          • @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

            – user2847643
            Feb 11 '18 at 21:42











          • @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

            – sclv
            Feb 14 '18 at 5:57








          3




          3





          My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

          – Carl
          Feb 11 '18 at 21:12





          My personal favorite is "just use cabal-install yourself, it's way easier than the horror stories would have you believe". It doesn't ever involve the platform, which is a rather poor idea in my experience.

          – Carl
          Feb 11 '18 at 21:12













          @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

          – user2847643
          Feb 11 '18 at 21:42





          @Carl I seem to remember a couple horror stories relating to cabal and cabal sandboxes from before I switched to stack and later to nix. To be fair that was before new-build though. Anyway hope I'm not exaggerating too much then.

          – user2847643
          Feb 11 '18 at 21:42













          @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

          – sclv
          Feb 14 '18 at 5:57





          @Carl the minimal platform, which is the recommended one these days, is just a one-stop-shop installer for ghc, cabal-install, stack, and the happy and alex tools.

          – sclv
          Feb 14 '18 at 5:57


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48733970%2fhow-to-install-haskell-platform-or-stack-in-2018-on-linux%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$