What a reader of each language needs first
A language is learned in the order its first week demands, and the two languages demand different things. C++ hands a beginner a toolchain that is older than most of its users and a first program that touches a header, a namespace and a return type before it prints anything. Haskell hands over one compiler, one file and one function, and then asks the beginner to believe that nothing in it can change.
This page is not a tutorial for either language. It is the short list of what has to be understood before the first useful program, so that a reader arriving from the other side knows what to read in which order.
The first program in both
In C++ the program includes a header for the function it calls, names it through std and returns an int from main. The compiler is told which standard to use, and the linker turns the object into a program:
#include <cstdio>
int main() {
std::puts("hello, world");
}
g++ -std=c++23 -Wall -Wextra -O2 hello.cpp -o hello
./hello; echo "status $?"
hello, world
status 0
In Haskell the program is a module with one function, and the function has a type. The compiler is the same program that runs it later; there is no separate link step in the invocation:
module Main (main) where
main :: IO ()
main = putStrLn "hello, world"
ghc -Wall -O1 -o hello-hs Hello.hs
./hello-hs; echo "status $?"
[1 of 2] Compiling Main ( Hello.hs, Hello.o )
[2 of 2] Linking hello-hs
hello, world
status 0
The toolchain you need first
One command answers the version question in each language. The three Haskell entry points are worth knowing from the first day: ghc compiles, runghc runs a file without a build, and ghci is the interactive shell where a beginner should spend the first hour. cabal arrives with the first project.
g++ --version | head -1
ghc --version
cabal --version | head -1
runghc --version
g++ (Alpine 15.2.0) 15.2.0
The Glorious Glasgow Haskell Compilation System, version 9.10.3
cabal-install version 3.16.0.0
runghc 9.10.3
The Glorious Glasgow Haskell Compilation System, version 9.10.3
The C++ side has the same three shapes with different names: the compiler, a build system (make or cmake) and a debugger. The differences that cost a beginner time are the ones nobody mentions: g++ needs the standard named, the header and the library are separate concepts, and the error messages of a template instantiation are longer than the program.
What a reader has to learn first
| Before the first useful program | C++ | Haskell |
|---|---|---|
| how code is organized | a translation unit, a header, a declaration and a definition | a module with an export list, and the layout rule instead of braces |
| how a value is passed | by value, by reference, by pointer, and who owns it | by value, always; a function returns a new value |
| what a statement is | an expression and a control structure, in a function body | there are no statements: a do block is an expression of type IO |
| how a program fails | an exception, a return code, or undefined behaviour | a value of type Maybe or Either, or an exception in IO |
| how a program is built | compile and link, then a build system | ghc, then cabal |
| what is undefined | a lot: the order of evaluation, an out-of-bounds access, a race | very little in safe code; laziness changes when, not whether |
The two rows that decide how long the first week takes are the second and the fourth. A C++ programmer arriving in Haskell has to stop changing values, which is a habit of every line rather than a rule to look up. A Haskell programmer arriving in C++ has to learn that a value can stop existing while a reference to it is still around, which is a habit of thinking about lifetime rather than a rule either.
What a team needs before it ships
A first program is a day; a first release is a month, and the cost is in different places. A C++ team needs a build system, an agreement about the standard and the compiler versions, a story for dependencies (which is a story about ABI), the sanitizers in the test build, and a reviewer who knows the lifetime rules. None of that is optional, and all of it is older than the language.
A Haskell team needs one GHC version per project, a package set that is known to build together (Stackage is the common answer), a test runner and a formatter, and a discipline about strictness in the places where it matters. The toolchain is smaller and younger, and the number of ways to configure it is smaller as a result; the library ecosystem is smaller too, which is the trade.
The two lists are short in both cases and they have nothing in common. A team that already has the C++ one pays nothing to start a C++ project and pays the whole Haskell list to start a Haskell one; a company that has hired for Haskell has the opposite arithmetic.
Coming from the other side
From C++ to Haskell. Read types first: the signature is the documentation and the compiler will hold you to it. Write small functions and let the type checker guide you; do not start with monads. Expect the compiler to be strict about warnings and use that. And expect to be surprised by laziness exactly once, in a program that is slower than it looks.
From Haskell to C++. Read lifetime first: who owns the value, how long the reference lives, what happens when a vector grows. Learn the sanitizers before the templates. Expect the compiler to accept programs that are wrong, and read the warnings it does print, because a -Wall warning in C++ is often the only thing between a program and undefined behaviour.
The Haskell course starts at what Haskell is and the second lesson installs the compiler; the C++ course starts at installing the compiler. The next page in this set is Tooling: ghc, cabal and hlint against g++ and the sanitizers.
The versions were printed by g++ 15.2.0 (Alpine 15.2.0), GHC 9.10.3 and cabal-install 3.16.0.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev