In this blog, we shall see how to set up a basic Haskell project and start running it.
You can install GHCI and Haskell using the ghcup installer.
Run the below script. It will ask for few prompts, you can go ahead with defaults, and the script will install the required modules.
After installing, the script would have added the path for ghci in the
rc file for your terminal. If not, you can add the below line your
rc file like
Glasgow Haskell Compiler is an interactive command-line compiler to run the Haskell code. Restart the terminal or source the rc file after the installation
Open your terminal and type
ghci . This will start the ghci on the terminal.
To stop the compiler, you can run
:qYou can find a bunch of commands here to play with the ghci compiler.
Let’s create a hello world project in Haskell. Haskell files are saved with the extension
.hs. Create a new file
intro.hs and copy the below contents into it.
Open the terminal and run
ghci . It will start the interactive Haskell compiler.
Load the Haskell file using
:l intro.hs . This will load the Haskell file into the ghci terminal. If you make changes to the file. Save it and run
:r in the compiler to reload your file.
Haskell is a pure functional language. I know it will be intimidating in the beginning for people from the Imperative Languages background like Java, C. But once you get a hold of it, It will be a smooth sailing from thereon. I hope this helps you to get started with Haskell setup. Happy Coding 👨🏻💻
Code Editor Support
You can also install the Haskell extension in vs code for code completion and other IDE features.