Baffled how to get a purescript repl installed

(My first q: apologies if I’m in the wrong place or being dumb.)

I’m very familiar with Haskell, am looking for a taster of purescript. I’m trying to install a minimal environment so I can run a repl similar to WinHugs. Oh, and I’m on Windows. I don’t know Javascript. (And if knowledge of Javascript is a prerequisite, I won’t bother going any further.)

Which instruction page should I be following? I went to this one: https://github.com/purescript/purescript/blob/master/INSTALL.md; clicked to ‘release’; downloaded/unpacked v0.14.05 win64.tar.gz

(That INSTALL page talks about ghc 8.10.7, which I already have; but it’s not clear why it’s relevant.)

At the Windows command prompt I can run … but
> purs --help
> purs repl --help
> purs repl
===> purs repl: No input files; try runningpulp psci instead.

And sends me to documentation/PSCi.md at master · purescript/documentation · GitHub
– which has commands that look like Unix (?) What is npm ? wikipedia talks about Javascript stuff. Did I need to install Javascript? Node.js what’s that? What is pulp? What is spago?

The bottom of that page has " PSCi Without Spago" saying purs repl but “expects you to have downloaded …” stuff.

The middle of that page “this guide” takes me to ‘getting-started’. More talk of Node.js and npm. What are EACCESS errors and why should I worry about them? And links that take me back where I started(?)

Can I not just get a prompt in the repl to try out some simple expressions? I was hoping for a single executable like WinHugs.exe or GHCi.exe.

1 Like

I suspect you arrived there through the repo - maybe we could add a pointer to installation instructions in the README.

If you land on the homepage you are prompted to install purescript and spago (through npm, that’s the recommended method).
After that you can just run spago repl and get a repl.
You’ll need Node installed, as the default repl runs JS code.

2 Likes

If you just want to try out some expressions I’d recommend starting out with https://try.purescript.org/.

The PureScript compiler doesn’t ship with the equivalent of base so to get a useful REPL, you’ll have to at least set up a small project using spago.
You don’t need to know JavaScript, but you do need NodeJS installed so that the REPL can run the compiled JavaScript.

There is a Quick Start Guide linked from the website, which should take you through the process step-by-step and get a minimal environment up and running.

(I hunted round various pages on the repo with (bits of) install instructions. It’s not clear which applies for a ‘minimal’ install on Windows. To compare with Haskell: I don’t want the full toolchain just to try out – and indeed I’ve never installed cabal nor stack – sounds like version hell.)

I suspect you arrived there through the repo - maybe we could add a pointer to installation instructions in the README.

If you land on the homepage

Having gotten confused by the inconsistent instructions in different places, yes I went from the homepage to ‘Get the compiler’/Binaries. Since I didn’t recognise the names of any of the other tools, but guessed they were equivalent to cabal/stack/etc, I’m trying to do without. (The Hugs download is an interpreter only; the GHC download includes gcc, but that’s hidden from you.)

you are prompted to install purescript and spago (through npm, that’s the recommended method).
You’ll need Node installed, as the default repl runs JS code.

I seem to have installed purescript – at least I can run it to get the --help. Of npm I know nothing beyond reading wikipedia (it sounds heavyweight), neither Node (.js presumably)

… as the default repl runs JS code.

So what’s with the page talking about GHC v 8.10.7?

The PureScript compiler doesn’t ship with the equivalent of base

Thanks, yeah I’d already seen that and worried I need to install a load of tools just to get a “hello world” running.

Ok this sounds too hard (on Windows, for someone with no interest in Javascript); I’ll give up.

I had already tried try.purescript.org – it didn’t seem promising. I’ll look again.

1 Like

PureScript is a little different than Haskell in that it doesn’t have its own runtime - it doesn’t output executables, it only outputs JS code*. So in order to have a REPL, the PureScript compiler turns the code you write into JS, and then something has to actually execute the JS code. That’s Node.js, the most prevalent JS runtime outside of the browser. Since you have to have Node.js installed in order to run PureScript code outside of the browser, the typical way of acquiring the PureScript compiler and build tools is through NPM, the Node Package Manager, which gets installed with Node.js.

The PureScript compiler is written in Haskell, so if you’re trying to build the PureScript toolchain from source you’d need GHC, but PureScript still just outputs JS code.

Spago is optional, I know there is a way to run the PureScript compiler and PSCi without spago, but spago does make things a lot simpler. I’m not sure what the steps are to running PSCi without spago.

I hope that clarifies why Node.js and NPM are required to run PureScript code on your local computer. If you don’t want a JS runtime installed on your computer, then you’d have to run PureScript via the browser, which is what try.purescript.org does for you.

* PureScript can also output code for other backends besides JS, like C and Python, but those are much less prevalent and much harder to setup.

2 Likes

Ok thank you. I’d pretty much figured that out by now, but good to have it confirmed.

try.purescript.org is at least letting me dip my toes in.

The ‘Differences from Haskell’ page was very helpful for me.

So purescript records are essentially the same as TRex, but with nicer syntax, because it’s not trying to co-exist with H98 style records.

Here is what I do to get a project quickly set up:

% cd $(mktemp -d)                         # Get a fresh directory
% npm install purescript pulp psc-package # Install necessary packages only for this directory
% PATH=$PATH:./node_modules/.bin psc-package init
Initializing new project in current directory
Using the default package set for PureScript compiler version 0.14.5
[...]
% PATH=$PATH:./node_modules/.bin psc-package install psci-support
[...]
psc-package.json file was updated
% PATH=$PATH:./node_modules/.bin pulp --psc-package psci
PSCi, version 0.14.5
Type :? for help

>