UMBC CMSC331-01&04, Programming Languages, Fall 2021


Running Haskell Programs


We will be using the Glasgow Haskell Compiler (GHC) using the command line interface. Here are some ways you can run Haskell.


On GL (default option)

The default option is to run GHC on GL. The Unix command to invoke the compiler is ghc. To run GHC in interactive mode, use ghci. These tools are already installed on GL, so nothing is required on your part. Use your favorite terminal emulator to log into GL and your favorite text editor to compose your Haskell source code.


On MacOS

MacOS is Unix underneath. So, you just need to install the GHC package. Since MaCOS does not come with its own package manager, you have to first install a package manager. The recommended package manager is Homebrew. Here are the steps:

  1. Go to the Homebrew web page and copy the Unix command under the heading "Install Homebrew". The command starts with
       /bin/bash -c "$(curl -fsSL ...
       

  2. Launch the MacOS Terminal app. Paste the command at the Unix prompt. Wait for Homebrew to finish installing.

  3. After Homebrew is done with its installation, you can install GHC:
       brew install ghc
       
If you already have another package manager installed (e.g., Macports or Fink), you can also install GHC using those package managers.


On Windows 10

The recommended procedure for running GHC on Windows is to use the Windows Subsystem for Linux (WSL). This will essentially give you Linux running under Microsoft Windows. Many things that you want to do with Linux can be accomplished in WSL. The exceptions are tasks that involve the Linux kernel. Also, WSL doesn't come with a GUI desktop, but you have Windows for that. WSL is provided by Microsoft and will not mess up your Windows installation. You can run Linux and Windows side-by-side. For most tasks, this is much easier than dual-booting Linux.

Steps:

  1. First make sure that WSL is enabled on your Windows system. From the Start Menu, search for "Turn Windows features on or off". Click on the Control Panel result from that search. This brings up a window with a bunch of checkboxes. Scroll to the bottom and see if the box for "Windows Subsystem for Linux" is checked. If not, check that box, click "OK" and reboot your machine.

  2. Go to the Microsoft Store and search for "WSL". Choose one of the Linux distributions available. Either "Ubuntu" or "Debian" is recommended.

  3. After Debian or Ubuntu is installed, launch the app. This will bring up a terminal window. Allow the system to do some housekeeping after the first launch. This could take a few minutes. You will be asked to create a super-user account and password. Remember this password! You will need the password to install packages.

  4. When the Linux distribution is ready, first update the packages:
       sudo apt update
       

  5. Next, install GHC
       sudo apt install ghc
       

  6. You will also want to install some Linux tools that might not be already installed, such as emacs, vim, openssh-client, rsync, ... These can be easily installed using the sudo apt install command.
If maintaining a Linux distribution is not your cup of tea, then just use GHC on GL. You can easily remove the Linux distribution by uninstalling the app (Debian or Ubuntu) that you downloaded from the Microsoft App Store.


On Android (not recommended)

Yes, you can run GHC on Android, but this is not for the faint of heart. The idea is that you install Termux and from within Termux install Ubuntu. Then, you can install GHC from the Ubuntu distro. The hiccup is that Termux is no longer supported on the Google Play store. So, you have to get the latest version of Termux from F-Droid. This is a small security risk, since you have to allow F-Droid to install apps on your device. Proceed at your own risk.

  1. First, on your Android device, go to the F-Droid site and download the F-Droid .apk file. Then, using your favorite Android file manager, install the .apk file. You may need to change your system settings to allow your file manager to install apps. (You can change it back after installing F-Droid.)

  2. Run the F-Droid app. Go to the updates panel. Update F-Droid itself, if available. You may need to change your system settings to allow F-Droid to install and update apps.

  3. In the F-Droid app, search for "Termux". Install the Termux app.

  4. Launch Termux. There are some housekeeping commands you need to issue:

  5. Now we can install Ubuntu inside Termux. Still in Termux:
          pkg install proot-distro
          
    When that is done
          proot-distro install ubuntu
          

  6. Now you can switch over to Ubuntu:
          proot-distro login ubuntu
          
    Inside Ubuntu, you should first update the distro:
          apt update 
          
    Then you can install GHC
          apt install ghc
          
    If your PATH environment variable is set up properly, you can run many Termux utilities from Ubuntu. Some installations like LaTeX will not work, because the directories are in the wrong places. You can install additional Ubuntu specific utilities using the apt install command, as usual.

  7. You can access Ubuntu files from Termux and vice versa. The Termux files are located in:
       /data/data/com.termux/files/home
       
    The Ubuntu files are in:
       /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu/root
       
    You can also access your Android files from Ubuntu using /sdcard.


Last Modified: 22 Jul 2024 11:28:11 EDT by Richard Chang
Back to Fall 2021 CMSC 331 Sections 01&04 Homepage