Motivation for this series
Navigating your way
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.
Get up and running in PureScript
You can skip this section if you've already installed and are using version 0.12.x PureScript on your computer.
Install PureScript and its supporting actors
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, and Psc-Package. As of this writing, I recommend you use the 0.12.0 version of the compiler. Before executing the following command, be sure you have the latest npm package manager and node installed.
npm i -g firstname.lastname@example.org pulp psc-package bower rimraf
You can check that these work by trying some commands:
pulp --version bower --version psc-package
Install editor plugins
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.
Run your first PureScript program
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:
$ mkdir purescript-hello $ 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>). You'll find more information on
My Favorite PureScript tools & references
- 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.
- psc-ide (distributed with the compiler) provides editor support, including atom, emacs, vim, and visual studio
I'll add additional links as I write the tutorials. But If you would like to look ahead, then the majority of the code samples from Brian's videos are available on Github. But I may amend them as I write the accompanying tutorial markdown.