Welcome, new Haskeller! Read on to quickly set up your Haskell development environment, execute your first lines of code, and get directions for further learning.
A complete Haskell development environment consists of the Haskell toolchain (compiler, language server, build tool) and an editor with good Haskell support. The quickest way to get this set up is to:
GHCup is a universal installer for Haskell that will install everything you need to program in Haskell, and will help you manage those installations (update, switch versions, …). GHCup does not require root/admin access. Follow the instructions on the GHCup webpage to install GHCup. Then use it to install the Haskell toolchain, which consists of:
Visual Studio Code (VSCode) is a popular choice with well-supported Haskell integration. Install the Haskell extension and you are all set. It should work out of the box and use your installation of HLS. To learn about support for other editors, check out HLS docs for editor configuration.
We have everything set up, let’s use it! The Haskell compiler, GHC, comes with an interactive interpreter called GHCi which is great for playing with Haskell and trying things out, so let’s give it a spin. Run
ghci at your command prompt, which will start a new GHCi prompt for you. Let’s do a simple calculation to check Haskell’s computing capabilities:
> 6 + 3^2 * 4 42
42 is a nice even number, but what about the first 10 even numbers after it?
> take 10 (filter even [43..]) [44,46,48,50,52,54,56,58,60,62]
What is the sum of those?
> sum it 530
NOTE: We used a special feature of GHCi here, which is a special
it variable that remembers the result of the last expression.
Great, you got the first taste of Haskell! Now let’s get to running a real program.
In your editor, create a new file named
hello.hs. Write the following in it:
= do main putStrLn "Hello, everybody!" putStrLn ("Please look at my favorite odd numbers: " ++ show (filter odd [10..20]))
You can now compile it with
ghc to produce an executable called
hello that we will then run:
> ghc hello.hs > ./hello Hello, everybody! Please look at my favorite odd numbers: [11,13,15,17,19]
There you go, you just wrote a short, polite program in Haskell!
GHCI TIP: You can also load your file directly into
ghci, which will enable you to play with any functions and other definitions you defined in it. So for our example, we can just load
hello.hs with GHCi and then call the function
main like this:
> ghci hello.hs GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hello.hs, interpreted ) Ok, one module loaded. > main Hello, everybody! Please look at my favorite odd numbers: [11,13,15,17,19]
By participating in the Haskell community you be able to ask for help and learn about new developments in the Haskell ecosystem. Some of the most popular places to interact with the community are:
We recommend joining right now, and don’t be shy to ask for help! Check https://www.haskell.org/community for a full list of resources relating to the Haskell community.
Popular free learning resources for beginners:
This is just the tip of the iceberg though: check Documentation for a bigger list of learning resources. That is it, fellow Haskeller! Enjoy learning Haskell, do (not?) be lazy and see you in the community!