UMBC CMSC331-01&04, Programming Languages, Fall 2022
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 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:
- 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.
- Go to the Microsoft Store and search for "WSL". Choose one of
the Linux distributions available. Either "Ubuntu" or "Debian" is
recommended.
- 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.
- When the Linux distribution is ready, first update the
packages:
sudo apt update
- Next, install GHC and the PCRE module
sudo apt install ghc libghc-regex-pcre-dev
- 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 MacOS
Updated 2022-09-02
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.
If you already have another package manager installed (e.g.,
Macports
or
Fink), you can also
install GHC using those package managers.
MacOS installation is complicated by three things:
- The steps vary a bit depending on which shell you use.
The Unix command to install Homebrew on their website works
for sh, bash and zsh. If you are using csh or tcsh, you should
fire up zsh (the default MacOS shell these days) to run
the Homebrew installation command. Also, for csh and tcsh,
each time you install something using Homebrew, you should
issue a rehash command to make the new command
available to you.
- The steps vary a bit depending on which version
of MacOS you have. The following has been tested on
Monterey (MacOS 12.5) and Big Sur (MacOS 11.6). Mojave
(MacOS 10.14) is not supported by Homebrew.
I have not checked Catalina (MacOS 10.15).
- None of Homebrew, MacPorts or Fink have the
PCRE package for Haskell as a library install.
We have to use Cabal, the native Haskell package
manager to get the Text.Regex.PCRE module.
Here are the steps:
- 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 ...
- Launch the MacOS Terminal app.
(Drop into zsh if you are using csh or tcsh.)
Paste the command at the Unix prompt.
Wait for Homebrew to finish installing.
- After Homebrew is done with its installation,
check if the brew command is available. If not,
follow the instructions to add the path to the commands
installed by Homebrew to your PATH environment
variable.
The actual path might vary depending on versions. It might be
/opt/homebrew/bin or /usr/local/bin.
If you are using csh or tcsh, manually add the path
in your .cshrc or .tcshrc file
instead of using the instructions provided by
the Homebrew installer.
Logout and log back in and check if the brew
command is available.
- Next, you can use Homebrew to install GHC:
brew install ghc
In addition to ghc, you need to install the PCRE module (Perl
Compatible Regular Expressions) for Haskell. This is somewhat more
complicated on MacOS since Homebrew does not supply the binaries and we
need to use cabal to download and install the package. This
means we need to install cabal and some system tools:
brew install cabal-install
brew install pkg-config
brew install pcre
Depending on which shell you use, you may need to issue the
rehash command to see the newly installed utilities. Then, we
can use cabal to install Text.Regex.PCRE:
cabal update
cabal install --lib regex-pcre
You can check if the Text.Regex.PCRE package was installed correctly by
running ghci and typing:
import Text.Regex.PCRE
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.
-
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.)
- 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.
- In the F-Droid app, search for "Termux". Install the Termux app.
- Launch Termux. There are some housekeeping commands you need to
issue:
- First, update Termux itself
pkg update
- Second, allow Termux to access the Android file system
termux-setup-storage
Your Android files are linked under storage or you can go
directly to /sdcard.
- Next, install any Linux utilities that you like using the
pkg install command. Termux has many but not all Linux
packages in its repository. In particular, it does not have GHC.
Hence the next step.
- Now we can install Ubuntu inside Termux. Still in Termux:
pkg install proot-distro
When that is done
proot-distro install ubuntu
- 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 and the PCRE module
apt install ghc libghc-regex-pcre-dev
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.
- 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:29:22 EDT
by
Richard Chang
Back to Fall 2022 CMSC 331 Sections 01&04 Homepage