Image for post
Image for post

Install Haskell on macOS

Step by step on my macOS High Sierra

Golden Thumb
Jan 23, 2020 · 5 min read

You cannot resist the charm of a functional programming language named Haskell.

YouTube video for GHC 8.10.1 on macOS Catalina 11.0.1
YouTube video for GHC 8.10.1 on macOS Big Sur 11.0.1
Enjoy the beauty of Haskell

Today I’ll try to install Haskell on one of my macOS computers — the old High Sierra. Note you need to be a registered Apple developer to install Command Line Tools.

This is my 10 years old macOS High Sierra:

Image for post
Image for post

Make sure I don’t have GHCi and Homebrew:

an-macair:~ donaldsheng$ ghci
-bash: ghci: command not found
an-macair:~ donaldsheng$
an-macair:~ donaldsheng$ brew install ghc
-bash: brew: command not found

Install Homebrew first:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Image for post
Image for post

I did press RETURN.

Image for post
Image for post

And typed in the login password and pressed Enter.

It took about 20 minutes on the above “Command Line Tools” stuff.

Image for post
Image for post

I also clicked Install button.

Image for post
Image for post

Yes I had to Agree.

Image for post
Image for post

Then … failed. :-(

Timed out while loading data from the Apple Software Update server.
==> Installing the Command Line Tools (expect a GUI popup):
==> /usr/bin/sudo /usr/bin/xcode-select --install
Password:
xcode-select: note: install requested for command line developer tools
Press any key when the installation has completed.

The reason could be that I have to install CommandLineTools for this old macOS in another way.

==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
Password:
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

This is the correct way — go to

https://developer.apple.com/download/more

to sign in as an Apple developer.

Image for post
Image for post

Follow the instructions on screen to trust the browser. My macOS version is 10.13 so I searched for “command line tools (macOS 10.13)”.

Image for post
Image for post

Double click highest Xcode version 10.1.

Image for post
Image for post

Download the dmg file.

Image for post
Image for post

Show it in Finder.

Image for post
Image for post

Double click the downloaded dmg file.

Image for post
Image for post

Double click the box to kick off installation.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

There is no need to keep Installer file. So I simply clicked “Move to Trash”.

Finally I could re-run the following command to install Homebrew.

an-macair:~ donaldsheng$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This time it worked like a charm.

Image for post
Image for post

With Homebrew, it’s easy to install Haskell.

an-macair:~ donaldsheng$ brew install ghc
==> Downloading https://homebrew.bintray.com/bottles/ghc-8.8.2.high_sierra.bottl
==> Downloading from https://akamai.bintray.com/33/3361eba5ff14c5ee50a90ee1090c0
############################################################# 100.0%
==> Pouring ghc-8.8.2.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/ghc/8.8.2/bin/ghc-pkg recache
🍺 /usr/local/Cellar/ghc/8.8.2: 6,731 files, 1.5GB

Make sure Haskell works:

an-macair:~ donaldsheng$ ghci
GHCi, version 8.8.2: https://www.haskell.org/ghc/ :? for help
Prelude> pi
3.141592653589793
Prelude> exp 1
2.718281828459045
Prelude> :q
Leaving GHCi.
an-macair:~ donaldsheng$

And if you love numbers as much as me, you can use cabal to install Haskell package “numbers”. Let’s install cabal first.

an-macair:~ donaldsheng$ brew install cabal-install
==> Downloading https://homebrew.bintray.com/bottles/cabal-install-3.0.0.0_1.hig
==> Downloading from https://akamai.bintray.com/72/72616fee2252d33d00e79ecd1778f
######################################################################## 100.0%
==> Pouring cabal-install-3.0.0.0_1.high_sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/cabal-install/3.0.0.0_1: 7 files, 27.5MB
an-macair:~ donaldsheng$

Run cabal update to download the latest package list from hackage.haskell.org.

an-macair:~ donaldsheng$ cabal update
Downloading the latest package list from hackage.haskell.org

Pretend to install numbers with —-dry option:

an-macair:~ donaldsheng$ cabal install --dry numbers
Resolving dependencies...
Build profile: -w ghc-8.8.2 -O1
In order, the following would be built (use -v for more details):
- numbers-3000.2.0.2 (lib) (requires download & build)

Actually install numbers:

an-macair:~ donaldsheng$ cabal install numbers
Resolving dependencies...
Build profile: -w ghc-8.8.2 -O1
In order, the following will be built (use -v for more details):
- numbers-3000.2.0.2 (lib) (requires download & build)
Downloading numbers-3000.2.0.2
Downloaded numbers-3000.2.0.2
Starting numbers-3000.2.0.2 (lib)
Building numbers-3000.2.0.2 (lib)
Installing numbers-3000.2.0.2 (lib)
Completed numbers-3000.2.0.2 (lib)
Warning: You asked to install executables, but there are no executables in
target: numbers. Perhaps you want to use --lib to install libraries instead.

Oops. OK, no problem — we do want to install libraries.

an-macair:~ donaldsheng$ cabal install --lib numbers
Resolving dependencies...
Up to date

With CReal, we can show 100 digits of 𝜋. So much fun! 𝜋ℯ𝝀𝜁 😂

an-macair:~ donaldsheng$ ghci
GHCi, version 8.8.2: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /Users/donaldsheng/.ghc/x86_64-darwin-8.8.2/environments/default
Prelude> import Data.Number.CReal
Prelude Data.Number.CReal> pi :: CReal
3.1415926535897932384626433832795028841972
Prelude Data.Number.CReal> exp 1 :: CReal
2.7182818284590452353602874713526624977572
Prelude Data.Number.CReal> showCReal 100 pi
"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068"
Prelude Data.Number.CReal> :q
Leaving GHCi.
an-macair:~ donaldsheng$

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data…

Sign up for Analytics Vidhya News Bytes

By Analytics Vidhya

Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Golden Thumb

Written by

1-on-1 tutor of chosen kids

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Golden Thumb

Written by

1-on-1 tutor of chosen kids

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store