You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/get-started.markdown
+33-38Lines changed: 33 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,21 @@ isGettingStarted: true
7
7
# Get started
8
8
Welcome, new Haskeller! Read on to quickly set up your Haskell dev environment, execute your first lines of code, and get directions for further learning!
9
9
10
+
## Content
11
+
-[Set up Haskell dev environment](#set-up-haskell-dev-environment)
-[Running first lines of code](#running-first-lines-of-code)
15
+
-[Writing your first Haskell program](#writing-your-first-haskell-program)
16
+
-[Join the community](#join-the-community)
17
+
-[Next steps](#next-steps)
18
+
10
19
## Set up Haskell dev environment
11
20
12
-
### GHCup - universal installer
21
+
### GHCup: universal installer
13
22
14
23
[GHCup](https://www.haskell.org/ghcup/#) is a universal installer for Haskell that will install for you everything you need to program in Haskell, and then will also help you manage those installations in the future (update, switch versions, ...).
15
24
16
-
It is simple to use, works the same way on all platforms (Linux, macOS, Windows), and gives you one central place/method to take care of your Haskell development setup.
17
-
18
25
Follow instructions at [GHCup webpage](https://www.haskell.org/ghcup/#) to install GHCup. Then, use it to install the Haskell Toolchain, which consists of:
19
26
20
27
1.**GHC** -> Haskell compiler. We will use it below to run our examples, but in practice, you will mostly be using a build tool like `cabal` or `Stack` to build your code, instead of `GHC` directly.
@@ -26,21 +33,11 @@ Follow instructions at [GHCup webpage](https://www.haskell.org/ghcup/#) to insta
26
33
<divclass="bs-callout bs-callout-info">
27
34
<p>
28
35
<h4>cabal and Stack -> which one should I install?</h4>
29
-
cabal is the original build tool, while Stack was created as an alternative to cabal a time ago to solve some of the problems that cabal had and provide a more user-friendly experience. In the meantime, cabal solved most of those issues (including "cabal hell") and caught up with Stack regarding user experience, so the main difference between them at the moment is how they resolve dependencies, which for you as a beginner isn't a concern. Therefore, both are a good choice, and if not sure, you can install both and then use whatever the learning resources you will later use will point you to.
36
+
We recommend installing both. Most Haskell projects can be built using Cabal, but some might require Stack. Installing both guarantees that you can use either, and while following the tutorial/book you can use whatever they recommend.
30
37
</p>
31
38
</div>
32
39
33
-
To confirm it is all installed correctly, you can run the following commands:
34
-
```
35
-
> ghc --version
36
-
> haskell-language-server-wrapper --version
37
-
> cabal --version # If you installed cabal
38
-
> stack --version # If you installed Stack
39
-
```
40
-
41
40
### Editor
42
-
HLS (Haskell Language Server), which you just installed via GHCup, is the one that brings all the cool IDE features to editors, so as long as your editor has a decent Haskell language extension that utilizes HLS, you are good.
43
-
44
41
**Visual Studio Code** is a popular choice with well supported editor integration. Install the [Haskell extension](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) and you are all set. It should work out of the box and use your installation of HLS.
45
42
46
43
Of other editors that have good Haskell extensions, the most popular ones are Vim and Emacs.
@@ -58,11 +55,10 @@ Let's do a simple calculation to check Haskell's computing capabilities:
58
55
> 6 + 3^2 * 4
59
56
42
60
57
```
61
-
Hey, they call Haskell lazy, but that was quick!
62
58
63
-
42 is a nice even number, but what about the even numbers after it? Let's get the first 10 even numbers after 42.
59
+
42 is a nice even number, but what about the first 10 even numbers after it?
64
60
```
65
-
> take 10 $$ filter even [43..]
61
+
> take 10 (filter even [43..])
66
62
[44,46,48,50,52,54,56,58,60,62]
67
63
```
68
64
@@ -77,42 +73,43 @@ Great, you got the first taste of Haskell! Now let's get to running a real progr
77
73
78
74
## Writing your first Haskell program
79
75
80
-
In your editor, create a new file named `hievb.hs`.
76
+
In your editor, create a new file named `hello.hs`.
81
77
82
78
Write the following in it:
83
-
```
79
+
```hs
84
80
main =do
85
-
putStrLn "Hi, everybody!"
86
-
putStrLn $$ "Pls look at my favorite odd numbers: " ++ filter odd [10..20]
81
+
putStrLn"Hello, everybody!"
82
+
putStrLn("Please look at my favorite odd numbers: "++filterodd [10..20])
87
83
```
88
84
89
-
You can now compile it with `ghc`, which will produce `hievb` binary that we will then run:
85
+
You can now compile it with `ghc`, which will produce `hello` binary that we will then run:
90
86
```
91
-
> ghc hievb.hs
92
-
> ./hievb
93
-
Hi, everybody!
94
-
Pls look at my favorite odd numbers: [11,13,15,17,19]
87
+
> ghc hello.hs
88
+
> ./hello
89
+
Hello, everybody!
90
+
Please look at my favorite odd numbers: [11,13,15,17,19]
95
91
```
96
92
97
93
There you go, you just wrote a short, polite program in Haskell!
98
94
99
95
**TIP**: To interpret the source file directly, without producing any build artifacts, you can use the special `runghc` command like this:
100
96
```
101
-
> runghc hievb.hs
102
-
Hi, everybody!
103
-
Pls look at my favorite odd numbers: [11,13,15,17,19]
97
+
> runghc hello.hs
98
+
Hello, everybody!
99
+
Please look at my favorite odd numbers: [11,13,15,17,19]
104
100
```
105
101
106
-
**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 hievb.hs with ghci and then call the function `main` like this:
102
+
**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:
107
103
```
108
-
> ghci hievb.hs
109
-
... Compiling ...
104
+
> ghci hello.hs
105
+
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
106
+
[1 of 1] Compiling Main ( hello.hs, interpreted )
107
+
Ok, one module loaded.
110
108
> main
111
-
Hi, everybody!
109
+
Hello, everybody!
110
+
Please look at my favorite odd numbers: [11,13,15,17,19]
112
111
```
113
112
114
-
**PRO TIP**: Once you progress a bit more in your Haskell journey, you will very likely want to use `cabal` or `Stack` for building your projects, and not `ghc` directly.
115
-
116
113
## Join the community
117
114
118
115
By joining the Haskell community you will find a great place to ask for help and learn about new developments in the Haskell ecosystem.
@@ -129,9 +126,7 @@ Check [https://www.haskell.org/community](https://www.haskell.org/community) for
129
126
130
127
## Next steps
131
128
132
-
There is a myth going around that you need Ph.D. in maths to be able to learn Haskell - and while it is true that Haskell in its elegance does often come close to the elegance of mathematics and borrows a lot of concepts from it, you certainly don't need any advanced math knowledge to be proficient with Haskell. Instead, what you need are some good learning resources!
133
-
134
-
Some popular free learning resources for beginners:
129
+
Popular free learning resources for beginners:
135
130
136
131
-[Introductory Haskell course of the University of Pennsylvania (CIS194)](https://www.seas.upenn.edu/~cis1940/spring13/lectures.html) (course)
137
132
-[Learn You a Haskell for Great Good!](http://learnyouahaskell.com/) (book)
0 commit comments