23 May 2019
6 min read
If you’re new to FP or you haven’t tackled Brian’s course, then I highly recommend that you do that first (I certainly did, and it helped me a lot). Then, once you understand the basic abstractions, come back and I’ll show you them in PureScript. I’ve done my best to explain the concepts, but Brian is a master at teaching them. Also, these tutorials are not a replacement for a good old fashioned PureScript primer. So take the time to learn a little PureScript syntax before diving head first into these tutorials.
Each tutorial has been placed in a separate folder named ‘tut##’, where ## is a number (e.g., ‘tut01’) that corresponds to video## from Brian’s course. You will also find the accompanying tutorial markdown (e.g., tut01/README.md) which illustrates the abstraction from Brian’s corresponding video (e.g., video1) and how to implement it in PureScript.
I have set up the folders so that you can run the PureScript code samples for the first time with
npm run all then
npm run exec from there on. There’s also individual scripts
npm run clean,
npm run install,
npm run build, and
npm run exec; used to clean, install, build, and execute the tutorial examples respectively. Naturally, this assumes you have (and you should) the
npm package manager installed. These scripts depend on
rimraf (the UNIX command
rm -rf for node),
Pulp (a build tool for PureScript projects),
Psc-Package (PureScript package manager), and the
Bower package manager. Note that
Bower is used in a couple of cases only. I will remove it, once Psc-Package captures all my module dependencies. All this is explained below.
You can skip this section if you’ve already installed and are using version 0.12.x of PureScript on your computer.
In earlier versions of this tutorial, I recommended you use Bower as your package manager. In fact, this is recommendation given in Getting Started with PureScript. Bower is useful, thanks to its flat dependency graph, and easy to use. However, its inability to restrict libraries that work with a specific compiler version of PureScript can cause problems for beginners. Especially during the early stages of a release of the compiler when libraries, tooling, and documentation are still catching up.
Instead, I recommend you use PureScript’s own
psc-package manager. The installation and usage are just as simple using Bower, so I see no good reason to use Bower when it is not necessary. Assuming you already have
npm running on your machine, here’s how to install PureScript, Pulp, Psc-Package, Bower, and rimraf. As of this writing, I recommend you use the 0.12.2 version of the compiler. Before executing the following command, be sure you have the latest npm package manager and node installed.
You can check that these work by trying some commands:
bower --version psc-package --version
There are plugins for most editors to support syntax highlighting, build support, REPL (Read, Evaluate, Print, Loop), and autocomplete. You’ll find the information to install these plugins for your favorite editor here.
Assuming you’ve installed PureScript, Pulp, and Psc-Package, then it doesn’t get any easier than this to start your adventure in functional programming with PureScript:
$ cd purescript-hello $ pulp --psc-package init $ pulp run
Pulp is an excellent build tool with plenty of helper options; such as watching for source file updates and re-compiling them automatically. As you add more library dependencies to your program, you can install them with
psc-package install <package-name>). You’ll find more information on psc-package here.
PureScript by Example by Phil Freeman the author of the PureScript language
Pursuit is the home of PureScript documentation; soon to become your best friend
Try PureScript allows you to try key examples of PureScript in the browser. You can also create your own.
I’ll add additional links as I write the tutorials. But If you would like to look ahead then most of the code samples from Brian’s videos have been ported to PureScript already and are available on Github. But I may amend them as I write the accompanying tutorial.
Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ
108 E 16th Street, New York, NY 10003
Join over 111,000 others and get access to exclusive content, job opportunities and more!