Haskell, as a popular language, does not have a simpleton IDE. So THE author recorded the process of setting up their own environment, hoping to help you.

The preparatory work

  1. A good network environment, at least to maintain a smooth connection to GitHub
  2. Homebrew

Setup of development environment

Compilers (GHC), interpreters (GHCI) and other Haskell toolchains

Haskell Stack is recommended for those who like a challenge. Brew Install Haskell Stack can be used for the GHC+GHCI+Cabal

The editor

At present, the mainstream editors include Vim, Emacs, Sublime, Atom, Visual Studio Code, etc. I only use them when modifying configuration files or replacing a certain string in my development.

IDE

Because Visual Studio, the best IDE in the universe, is late and not performing well on the Mac, I recommend IntelliJ IDEA(although I hate Java, I have to admit that there are many useful tools written in Java).

HaskForce

IntelliJ IDEA has two third-party plugins that provide support for Haskell. I recommend using the highly rated HaskForce plugin, which is currently unmaintained (doubtful, but also a reflection of the current state of the Haskell community).

  • The installation

    1. Press ⌘ + in IntelliJ IDEA to enter the preference setting screen
    2. Plugins > Browse repositories > HaskForce

  • Due to the limitations of the HaskForce plug-in itself, projects need to be created in the terminal using the Haskell Stack.

    1. Stack new Project name Template name path (default current path)
    2. CD Project Name
    3. stack setup
    4. stack build

Notice If a warning message is displayed indicating insufficient parameters during project creation, run ~/. Stack /config.yaml

templates:
    params:
        author-name: your-name
        author-email: your-email
        copyright: "Copyright (c) 2018 0x11901"
        github-username: "0x11901"
        category: categories
Copy the code

It is not recommended to write the template name here. If you are not sure what template to use, you can pass Simple

  • Import the Haskell Stack project created using IntelliJ IDEA
  1. The path selects the root directory of the project and makes sure that the Stack module is selected
  2. And then all the way to the next step
  3. Configuration configurations
  4. > Add > Haskell Stack Run > Executable: project name
  5. Executable must be completed
  • Click Run to run your Haskell program!

Related tools

If only these can be pleasant coding, but I think it is not enough. After all, I wouldn’t write code without a code formatting tool and a static code analysis tool. So how can you miss these!! It just so happens that HaskForce integrates related Haskell tools like HLint, GHC-MOD, Hindente, etc., and works well with IntelliJ IDEA. They are also easy to install and can be installed using Haskell Stack, while HLint can also be installed using Homebrew, although I recommend a unified installation for future administration.

stack install hlint hindente stylish-haskell

The installation of GHC-MOD deserves special mention, The default Haskell Stack resolver is LTS-11.6, and the GHC version is 8.2.2. The ghC-mod is not supported by the Haskell Stack resolver, so it is difficult to compile it successfully. So if you want to work with this delightful hack, follow these steps to compile it.

1. It is recommended to create a separate directory to store the files to be used next. Compilation can delete 2. After the completion of the CD you just build directory (3) the git clone https://github.com/DanielG/ghc-mod.git - b ghc802 4. Git clone https://github.com/DanielG/cabal-helper.git 5. cd ghc-mod ; touch stack.yamlCopy the code

Since compiling GHC-mod with Haskell Stack requires a stack.yaml configuration, open stack.yaml with your favorite compiler and write the following:

resolver: LTS - 11.6 - # current resolver

packages:
    - location: .
    - location: ./core # seems like ghc-mod-core got integrated
    - location: ../cabal-helper
      extra-dep: true

extra-deps:
    - Extra - 1.6.6 # escapeJSON was missing with 1.5.3
    - Monad - journal - 0.7.2
    - Optparse applicative -- 0.13.2.0
    - Unix - compat - 0.4.3.1
    - Either - 4.4.1.1
    - Cabal - plan - 0.3.0.0

flags: {}

extra-package-dbs: []

allow-newer: true # so it builds / too lazy to pinpoint exact versions
Copy the code

Ghc-mod and MODI will be installed in the ~/. Local /bin directory using stack install. You can add these directories to shell environment variables or move them to directories already added to shell environment variables.

Finally, open the IntelliJ IDEA entry preferences screen, go to Haskell Tools, then Find the Tools you want to use, click Auto Find button and confirm, you can use these Tools in IntelliJ IDEA!

Haskell IDE Engine

I recently found out about this new project on GitHub, and compared to HaskForce’s unmaintained state, the project is in full swing. As described in the project introduction, this Haskell engine integrates all of the tools mentioned above and is much dumber to install and configure. For maintainability, I recommend this solution for those considering configuring a Haskell environment.

Haskell IDE Engine integrates with Visual Studio Code

From the introduction of Haskell IDE Engine, it can be seen that the author is designed in accordance with the mode of “editor + HIE”, so this time the author tries the combination of Haskell IDE Engine + Visual Studio Code. The main reason for choosing Visual Studio Code is that it’s free, because I’m poor. Their integration is also simple: install Haskell Language Server from VSCode marketplace, then compile HIE yourself. HIE can be compiled according to the GHC version you use, but according to Haskell Language Server, it is recommended to compile all of them, so the author chooses full compilation:

git clone https://github.com/haskell/haskell-ide-engine --recursive
cd haskell-ide-engine && make build-all
Copy the code
  • Haskell Stack version >= 1.7.1 is required
  • A smooth network

After a successful compilation, the binary file will be placed in ~/. Local /bin. You are advised to add this PATH to $PATH. Finally, you only need to open VSCode preferences and configure them in JSON. For details, please refer to the documentation of Haskell Language Server. Basically, the default Settings are ok. But there’s also “languageServerHaskell useHieWrapper” : True field can choose to open, if you don’t have the binaries of HIE in $PATH, also need to configure “languageServerHaskell. HieExecutablePath” : “” field.

Now you can have fun with VSCode.

Afterword.

Haskell IDE Engine also supports a wide range of editors. Although it is not as good as the combination of HaskForce + IntelliJ IDEA now, from the perspective of development, Haskell IDE Engine should dominate in the future. So the author suggests that everyone can try, in short, the current use or more satisfied, above.