How can one install Haskell on macOS?
by Yours Truly
Why not about TempleOS, patching KDE under FreeBSD, or what have you
Haskell is an awesome functional programming language, and this post being an inaugural one for this blog could not have possibly been about anything else.
Functional languages naturally give a feeling of being as generic as possible providing
all the facilities to be as close to mathematics as one’s code could be. The Stokes’ theorem
works for a whole lot of differential forms and manifolds and no sightings of if
statements, loops, etc at all:
And that helps designing microwave ovens and antennas, true story!
If only there was a way to deal with complexity like that in software engineering: create good abstractions and the rules of combining them to have less code! Wait, that is what functional programming is about!
An example of some Haskell might be the quick sort:
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
Woah, that is way shorter than in C! Truth be told, C allows cutting some corners to make things faster. On another hand, developing and supporting 6 lines of code does have its merits. Not that you’ll have to write quick sort yet less code and being generic are always going to be there.
Enough preaching though, we were going to install something, weren’t we?
How one can install Haskell on macOS!
I’ve tried various approaches and the following appears to provide the
well-organized setup with just one package installed via Homebrew
, and
everything else goes under ~/.ghcup
and ~/.cabal
.
brew install ghcup
ghcup tui
for a nice TUI-driven selection of the tools. In the list, use the arrow keys ↑ ↓ to select the component and i to install.ghc
is the compiler,hls
is the language server provider, andcabal
is the package and project manager.export PATH="$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH"
goes into your shell’s rc file.- Get versions with
ghcup list
and set defaults withghcup set ghc 9.10.1
,ghcup set cabal 3.12.1.0
, etc.
As a side note, rustup
and cargo
in the Rust ecosystem have been influenced
by ghcup
and cabal
from the looks of it. Good for Rust! Oh, and the Haskell
package repository aka Hackage appears to have given
some ideas to crates.io.
My favorite books on Haskell
- Thinking with types
- Get Programming with Haskell
- Learn Physics with Functional Programming: A Hands-on Guide to Exploring Physics with Haskell
- Algorithm Design with Haskell
- Haskell for FPGA Hardware Design
If you’re just starting out, then give a read to Learn You a Haskell for Great Good A Beginners Guide
Am I using that?
At home, yes, I am. It’s fun to figure out the solution for dynamic programming problems :) At work, no, I am not. The work stuff requires top performance and the ability to program hardware, and Haskell might not be the best tool for any of that.
All told, hoping to talk about some hardcore system stuff on the blog soon!