🍗 Wiki

Haskell

Haskell

1. Try or Install

1.1. Try

In the official Haskell homepage provides the try-it-online repl.

$ nix-shell -p ghc
...
$ ghci
GHCi, version 9.6.4: https://www.haskell.org/ghc/  :? for help
ghci> "Welcome" ++ " " ++ "Ch1keen" ++ " " ++ "Wiki"
"Welcome Ch1keen Wiki"
ghci> "Welcome" ++ " " ++ "to" ++ " " ++ "Ch1keen" ++ " " ++ "Wiki"
"Welcome to Ch1keen Wiki"
ghci>

2. Write a simple script and run

ghc command let you compile a script, and run the compiled binary. No need to set up a project.

Let’s write a simple Haskell script, which just prints "Hello World" to the console.

-- Hello.hs
main = putStrLn $ "Hello" ++ " " ++ "World"
$ ghc Hello.hs
[1 of 2] Compiling Main             ( Hello.hs, Hello.o )
[2 of 2] Linking Hello
$

If there were no error, three files will be created, an interface file Hello.hi, an object file Hello.o, and the executable Hello.

Then run the executable as normal.

$ ./Hello
Hello World
$

3. Start a new project

3.1. With Stack

Stack is a project manager, provides an isolated environment, and is widely used in nowadays.

4. Trivia

  • There was an IDE, dedicated to writing Haskell code and most of its code is written in Haskell, called Leksah.

    • Sadly, despite people attention, it is nearly dead project since 2022.