Getting Started with PureScript
Giving PureScript a try isn’t too much of an afford. As PureScript completely runs on top of Node.js, all we need to do is installing the related NPM packages. Once it is installed, we can bootstrap a new project. Finally, we can compile to code to JavaScript. All of this happens on the basis of Node.js.
Installing PureScript on your machine:
npm install -g purescriptnpm install -g spagoFor transpiling to JavaScript, we need esbuild locally:
npm install -g esbuildCreating a new project: (Make sure to first create an empty directory, spago will set up in the current dir)
spago initRunning:
spago runBuilding for the web:
spago bundle-appGetting started the recommended way
Section titled “Getting started the recommended way”This way avoids a global installation of PureScript to ensure working with multiple projects in different versions.
(Make sure to first create an empty directory, spago will set up in the current dir)
npm init -y
npm install --save-dev spago purescript
# to check whether installation works:npx spago versionAs you can see, using NPM like this only installs Spago and PureScript locally, for development - bound to your project.
Then, using NPX you can initialise the PureScript project just like before:
npx spago init
npx spago run
npx spago runYou can start the REPL with “spago repl”.
You can import any module from the src-directory with: “import Module” For example, “import Main”.
From now on, you can access data written in the file in the REPL. Whenever you change something in the file, make sure to reload the REPL: ":reload".
To quit: ":quit".
Getting the type of some data: ”:type data”
Great ressources for PureScript
Section titled “Great ressources for PureScript”- The official PureScript book
- Jordan’s notes
- Pursuit
- Functional Programming Made Easier - Book. There is a free sample which is awesome
The FP made easier book also serves as the original source of knowledge for this cheatsheet.