How to install Haskell programming in Ubuntu Linux?


Haskell is a general purpose, modern, statically typed purely functional programming language. It was designed for teaching, research, and industrial application.

Initially, it was released in 1990 and named after US mathematician Haskell Brooks Curry.

Today in this article I will discuss how to install and set up the Haskell programming language on Ubuntu Linux.

Prerequisites

To follow this guide you should have the following –

  • A system running a recent version of Ubuntu Linux
  • Access to a user account that has superuser privileges

How to install Haskell in Ubuntu

The Haskell programming includes the following toolchain –

  • GHC – The Glasgow Haskell Compiler
  • Cabal-install – The CABAL or Common Architecture for Building Applications and Libraries is used to manage Haskell software
  • Stack – This is a cross-platform program for managing Haskell software
  • Haskell language server – A language server for developers to integrate with their editor/IDE

Instead of installing these packages separately, we will use haskell-platform package for installing everything required for Haskell programming in Ubuntu Linux.

Before installing any packages use the given command to update the apt package repository –

sudo apt update

Next, use the given command to install Haskell on your system –

sudo apt install haskell-platform

Press y and then enter if it asks for your confirmation.

Once it gets installed use the following command to view the Haskell compiler version –

haskell-compiler --version

haskell compiler version

Writing your first Haskell program

After it gets installed you can write your first Haskell program, first, execute the given command to start the Haskell compiler in the interactive mode in your terminal.

ghci

ghci

Now here you can write and execute your Haskell programming statement as you can see in the image below.

execute haskell

You can also execute a Haskell program file, first open a text editor by using –

nano hello.hs

Write the given code inside it –

main = putStrLn "Hello, World!"

Do not forget to save this file with the .hs extension.

Compile the code by using the given command  –

ghc -o hello hello.hs

On successful compilation, you will see output something like given in the image below –

haskell compile

Next, execute the hello world program by using –

./hello

This will display the given output.

output

How to remove Haskell from Ubuntu

For any reason, if you want to remove Haskell from your Ubuntu system then use the given command –

sudo apt remove haskell-platform

Press y and then enter if it asks for your confirmation.

Remove any unused dependencies from your system by using –

sudo apt autoremove

Conclusion

Ok, so you have successfully installed Haskell programming on your Ubuntu system.

Now if you have a query or feedback then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.