To use PureScript's PSCi, we must make sure that we have the Bower dependency installed, which is PureScript PSCi support. I'm going to demonstrate PSCi using Pulp by typing in pulp psci from within your project directory. PSCi is simply PureScript's REPL, and is a great playground to explore your code.
Let's have a quick look at the help section by typing in :?. I'll zoom out a little to make this clearer. As you can see, all the tools that come with PSCi start with colon, and then the expression name. Let's explore two of these tools.
Here, we have :type, which will show the type of your function. Here is :reset. This will reset your imported modules. I'm going to clear my terminal, and now try some simple arithmetics. One plus one. That's weird. PSCi has just returned an error.
It looks it has an unknown operator of plus. Why is that then? Well, the PureScript call is, in fact, really small. Most of its functionality needs to be imported via dependencies. One of these is called Prelude, and it's an important core dependency which you'll most likely use in every module.
To do this, you simply type import Prelude, with a capital P. What you're doing here is exactly the same as you were inside a PureScript file. Let's have a quick look at one of these. We'll go into our src folder, and open up our Main.purs. Here, you can see import Prelude.
Back to PSCi. Now, doing one plus one will return two.
Now, let's demonstrate how we can use PSCi to become a playground for a module that you're working on. Here, we've named our module Main. We'll go back into PSCi, and we'll import that by typing import Main, remembering to have a capital M, as we do in our file.
Now, looking at the type definition of our function main, what you can do is use PSCi to display that function definition. You simply type in :type main, and there you have. It's exactly the same as within our file, though the layout is a little different.
You'll find yourself using this often. What you can do is just use :t. Now, we've seen the type of our function. Let's run it. All you've got to do is just type in the name of the function, which is main. That'll log, "Goodbye my poor sailor!"
I'm going to make a change in the file to demonstrate how we can still use PSCi to test that change. Let's change the string to that log to, "You will make it back safe sailor!" This is turning into a right love story.
Let's save our file, and go back into PSCi. We'll use one of our helpers, which is :reset. This will reset all of our imported modules. It spotted a change, and recompiled Main. You can reimport it, then run the function main.
There you go. It's outputted the change that we made inside our file. Now, you can see that PSCi is a great playground to experiment with your code.