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: guides/Getting-Started.md
+15-13
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,11 @@ Let's walk through the basics of getting set up to use the PureScript compiler `
4
4
5
5
We'll start with the installation of the compiler and Spago build tool, and then go through the basic usage of `purs repl`, working towards a solution of problem 1 from [Project Euler](http://projecteuler.net/problem=1).
6
6
7
-
####Installing the Compiler
7
+
### Installing the Compiler
8
8
9
-
You'll need to install [Node.js and npm](https://docs.npmjs.com/getting-started/installing-node). We recommend installing [Node.js and npm via a node version manager](https://docs.npmjs.com/getting-started/installing-node) to avoid issues with installing packages globally. If you choose to install it manually, you might experience the [`EACCES` error when installing packages globally](https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-1-change-the-permission-to-npm-s-default-directory).
9
+
There are many [installation options](https://github.com/purescript/purescript/blob/master/INSTALL.md), but we recommend using `npm`.
10
+
11
+
[Install Node.js and npm via a node version manager](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm#using-a-node-version-manager-to-install-nodejs-and-npm). Using a node version manager helps avoid [`EACCES` errors](https://docs.npmjs.com/getting-started/fixing-npm-permissions) when installing packages globally (as we'll do in the next step).
10
12
11
13
Install the Purescript compiler (`purs`) with npm:
12
14
@@ -16,9 +18,9 @@ Try running the PureScript compiler on the command line to verify that the PureS
16
18
17
19
purs
18
20
19
-
It can also be installed from [Hackage](http://hackage.haskell.org/package/purescript), or by downloading the latest [binary bundle](https://github.com/purescript/purescript/releases) for your OS. If you do so, make sure the `purs` executable is on your `$PATH`.
21
+
If you encounter problems during installation, see the compiler's [Install Guide](https://github.com/purescript/purescript/blob/master/INSTALL.md) for troubleshooting suggestions.
20
22
21
-
####Setting up the Development Environment
23
+
### Setting up the Development Environment
22
24
23
25
[Spago](https://github.com/spacchetti/spago) is the recommended package manager and build tool for PureScript.
24
26
@@ -54,15 +56,15 @@ You should see output similar to the following:
54
56
55
57
If everything was built successfully, and the tests ran without problems, then the last line should state "Tests succeeded."
56
58
57
-
####Installing Dependencies
59
+
### Installing Dependencies
58
60
59
61
Dependencies can be installed using Spago. We will be using the `lists` library shortly, so install it now:
60
62
61
63
spago install lists
62
64
63
65
The `lists` library sources should now be available in the `.spago/lists/{version}/` subdirectory, and will be included when you compile your project.
64
66
65
-
####Working in PSCI
67
+
### Working in PSCI
66
68
67
69
PSCi is the interactive mode of PureScript. It is useful for working with pure computations, and for testing ideas.
68
70
@@ -117,7 +119,7 @@ We will be using some of the functions from the `Prelude` and `Data.List` module
117
119
118
120
Note that using `Tab` to autocomplete names can be a useful time-saving device in `psci`.
119
121
120
-
####Solving Project Euler #1
122
+
### Solving Project Euler #1
121
123
122
124
The following problem is taken from [Project Euler](http://projecteuler.net/problem=1):
123
125
@@ -159,7 +161,7 @@ When you have finished using PSCi, type `:quit` to quit:
159
161
> :quit
160
162
See ya!
161
163
162
-
####Compiling a Solution
164
+
### Compiling a Solution
163
165
164
166
Now that we've seen how to use the REPL to reach the answer, let's move our solution into a source file and compile it.
165
167
@@ -202,7 +204,7 @@ This will compile each module present in `src/` into a separate file in the `out
202
204
203
205
The compiler will display several warnings about missing type declarations. In general it is considered good practice to provide explicit type signatures. In this guide, they are left out for brevity. In the absence of type signatures, the PureScript compiler infers types automatically but will remind us to consider adding them.
204
206
205
-
####Writing a Test Suite
207
+
### Writing a Test Suite
206
208
207
209
To test our code, we'll use the `assert` library:
208
210
@@ -226,7 +228,7 @@ Our "test suite" is just a single assertion that the `answer` value equals the c
226
228
227
229
Run the tests using `spago test`, and you should hopefully see "Tests OK" in the last line.
228
230
229
-
####Creating Executables
231
+
### Creating Executables
230
232
231
233
We can modify the `main` function in the `src/Main.purs` module to print our result to the console:
232
234
@@ -249,7 +251,7 @@ The `spago run` command can be used to compile and run the `Main` module:
249
251
The answer is 233168
250
252
251
253
252
-
####Compiling for the Browser
254
+
### Compiling for the Browser
253
255
254
256
Spago can be used to turn our PureScript code into JavaScript suitable for use in the web browser by using the `spago bundle-app` command:
255
257
@@ -310,7 +312,7 @@ This illustrates a few points about the way the PureScript compiler generates Ja
310
312
311
313
These points are important since they mean that PureScript generates simple, understandable code. The code generation process, in general, is quite a shallow transformation. It takes relatively little understanding of the language to predict what JavaScript code will be generated for a particular input.
312
314
313
-
####Compiling CommonJS Modules
315
+
### Compiling CommonJS Modules
314
316
315
317
Spago can also be used to generate CommonJS modules from PureScript code. This can be useful when using NodeJS, or just when developing a larger project which uses CommonJS modules to break code into smaller components.
316
318
@@ -322,7 +324,7 @@ To build CommonJS modules, use the `spago build` command:
322
324
323
325
The generated modules will be placed in the `output` directory by default. Each PureScript module will be compiled to its own CommonJS module, in its own subdirectory.
324
326
325
-
####What Next?
327
+
### What Next?
326
328
327
329
If you're new to typed functional programming, your next stop should be [PureScript by Example](https://book.purescript.org/), which will walk you through learning PureScript by solving practical problems.
0 commit comments