I am a cryptocurrency investor, developer, miner and bitcoin professional certified by C4. Among several researches and enthusiasm on crypto world, there is a project that is my favorite. The name of this project is Cardano and brings a cryptocurrency called ADA. Cardano is a project involving several scientists, professors of renowned universities and system architects that created over 40 high quality white-papers describing the network synergy. Cardano and its products are being developed by a company called IOHK in collaboration with open source community and other third-party companies. According the founder and CEO of IOHK, Charles Hoskinson, Cardano is classified as a cryptocurrency generation 3, based on PoS (Proof of Stake), smart-contracts with a decentralized network but much more scalable and sustainable when compared to old generations like Bitcoin and Ethereum.
Most part of the code is based on Haskell which is a functional language that works in a very different way when we compare with sequential and imperative languages like C, C++, Java, etc.
The idea of this post is to create a guide how to integrate Haskell with Atom editor on Ubuntu OS and help you to learn Haskell fast with a good IDE. The Ubuntu distro used on this post was version 19 but you also can use the procedure explained on this post in older versions as well.
More information about Cardano (ADA) please visit: https://www.cardano.org
Before we start!
The procedure here will be using Stack tool set for Haskell. I literally was not able to make that work with GHC compiler superior to 8.0.2 due to several dependence of ghc-mod which is used as intermediary between the back-end (Stack) and or front-end (Atom).
If you are already using Stack you can skip the step 1 going directly to step 2.
Step 1) Installing Haskell
Basically there are 3 ways you can install Haskell:
- Stack: this is the method we will use here. Stack is a package manager and build tool that creates a “sandbox” of Haskell and its respective tools isolating everything you have installed in your system. For example, if you have a Haskell compiler (GHC) installed in the system, when you install stack another compiler is installed in the sandbox and your compiler in the system is not “touched”. Optionally you can integrate with your compiler in the system but it is not what we will do here.
- Hashkell-Platform: this definetly it is the easiest way to install haskell on ubuntu (sudo apt-get install haskell-platform) but this also brings several problem when integrating the Atom that I will explain later. Basic when you install the platform, the compiler and other tools are installed in the system OS and not in a sandbox like Stack.
- Cabal: It is similar to stack but cabal also can be installed via stack and we will see in the next steps. You can install cabal using stack
To install stack open a terminal and type:
After the installation it is recommended to add the path of stack in your profile. For example, if you are using bash, open the .bashrc file and include the path in the system path like below:
Check the version of the compiler installed:
Step 2) Installing the ghc-mod properly
If you try to install the ghc-mod using Stack without any extra specification (i.e., stack install ghc-mod) you will realize there are several dependencies that must be resolved. You have two option on this case, the first one if to specify during the installation the lts compatible to ghc-mod. This will force to have all dependencies resolved.
The second way is to install the dependences one by one and change the stack.yaml in the ~/.stack/global-project/stack.yaml. Sorry guys, it is Saturday night and I am very lazy today, I will use the method above using the resolver.
Step 3) Installing Cabal via Stack
OK… super simple.. just type:
Step 4) Testing your installation
If you achieve this step without problems, congrats!!! Your “back-end” is already installed and let’s test it creating a Hello World project. The cool thing is stack brings some templates that helps you during the creating of your project. We will use the template “simple” that brings a “Hello World” program.
check the source code:
Let’s run.. make sure you have the “setup” and then “build” it!
Finally run !!!!
Step 5) Installing Atom
Let’s install our “Front-End” that will use the ghc-mod to communicate with the stack.
If you already have Atom installed just jump to step 6.
In Ubuntu 19, you simply can type in your console
In case you do not have snap in your distro, you can install it symply typing:
sudo apt-get install snap
Step 6) Installing Atom plugins
There are two ways to install the plug-ins.. via UI or via command line using the apm (Atom Package Manager). I will do it in the fast way.. just type:
Step 7) Testing Atom with Haskell IDE (Finally……)
Let’s run the editor.. in your console type “atom”
In the editor, open the Main.hs file generated when we created the project. To do this, press “ALT” key to see the menu and File –> Open File and locate the Main.hs we created before.
If you pressed the “ALT” key and do not see the menu, you are probably is using Ubuntu 18 or 19. There is a trick to fix this issue (not an Atom issue indeed), on this case see the last section “Troubleshoot”.
After you open the Main.hs, clique on ALT key again and select
Haskell IDE -> Builder -> Set Active Builder
Select “Stack” as your default option.
Now you are ready to build… Again after the ALT select:
Haskell IDE -> Builder -> Build Project
You should see your project compiled without problem as below:
Now you have the IDE ready to your Haskell code!!! Explore the auto-completiton, the syntax highlight, and several other options. For more details visit this link: https://atom-haskell.github.io/
If you are not seeing the menu after press the key “ALT” you probably is using Ubuntu 18.04 or 19. There is a problem on this distro not Atom, but this is easily resolved changed the theme. For this install and run the following:
Change the application theme appearance from “Yaru” to “Yaru-Dark“. The problem will be resolved.
Did this post helped you ?
You can buy me a coffee in ADA. Please use the address below:
Donate Cardano to this address
Scan the QR code or copy the address below into your wallet to send some Cardano