In this lesson, we will learn how to run Purescript with a simple log statement. We use pulp to compile Purescript down to readable javascript.
[00:00] To get started with Purescript, you must npm i -g purescript pulp bower. This will globally install these packages. Now, it's time to use the pulp which we just installed, it's a build of Purescript, and you use it by doing pulp init. This will generate a set of files to get us started on a basic project.
[00:20] One of these files is a bower.json. Let's have a look at it. Purescript packages are all installed via bower, and pulp is installed for us the prelude, the console and psci-support. Let's take a look at what else pulp has generated for us.
[00:34] In specific, let's look at our source folder where there is our main.purs, .purs being a file extension used by Purescript to determine its files. All Purescript files require them to be modules. In this case, you can see it's module Main where, Main being the name of our module.
[00:50] We have our imports prelude, an Eff, and a console, then beneath that is a function. This line is our function definition which shows the types of the functions.
[01:01] A high-level overview of types is it shows you exactly what the function performs, its inputs and its outputs. Lowercase m being the name of our function, and you can see it uses a log, along with a string of "Hello sailor!"
[01:14] What exactly does it do? Well, time to use pulp to compile our files and run our program. To do this, you do pulp run. After the Build successful, you'll see our line, "Hello sailor!" This log comes from our main module, and I'll demonstrate that by changing it.
[01:29] Let's change this line to, "Goodbye my poor sailor!" and rerunning pulp run. Now, you can see our change has been made right here. When I mentioned our files are compiles, what exactly do I mean? Well, Purescript compiles to JavaScript. What this means is pulp generates an output file, and if we scroll down to Main folder for our module, inside of it, you'll see an index.js.
[01:55] Let's open this file, have a look inside. Here, you can see the function var main, and it has a .log "Goodbye my poor sailor!" which is the same as our terminal log.
[02:07] A great feature of Purescript is that it compiles down to readable JavaScript. There you have it, your first "Hello world!" -- well, technically "Hello sailor!" -- in Purescript.