Getting to know Purescript (from Elm)

So, Purescript.

If you know Elm and want to add to your toolset a language, which actually has those higher abstractions that you've heard about, Purescript is the obvious choice.

Purescript compiles to Javascript too, it can interoperate with any Javascript library, has no runtime, and has most of those Haskell abstractions, plus a few more.

So in exchange for the time you're going to sink into learning those abstractions, you get a more flexible and lightweight language, which can interoperate more easily with any Javascript library you may need.

Sounds like a good deal to me.

Elm is optimised for simplicity, which is great when you want to get something done, but it can feel constrictive when what you want to do turns out awkward or impossible.

When you're a bit fed up with that, it's probably time for the next step on the ladder.
And I think that is Purescript. (YMMV)

Install

If you're on a Mac/Linux the following commands should work as they are:

  • get the latest bower (dependencies tracking)
$ npm install -g bower
  • get the latest pulp (build tools)
$ npm install -g pulp
  • get the latest version manager
$ npm install -g psvm
  • install the file watcher
$ npm install -g pscid
  • install latest with psvm
$ psvm install v0.9.2
$ psvm use v0.9.2

From now on you'll have the various purescript commands:

psc   psc-bundle  psc-docs  psc-ide-client  psc-ide-server  psc-publish psci

add $HOME/.psvm/current/bin to your $PATH if you can't access them.

  • make a proj
$ mkdir myproj
$ cd myproj
  • test pulp
$ pulp init
$ pulp build
$ pulp run
  • to install a dependency:
$ bower install purescript-math --save
  • start the file watcher:
$ pscid

You can start to edit this barebones project with your favourite editor. I'll make an emacs install guide in the future.

Book

The obvious way to learn Purescript is by reading the "Purescript by example" book, which has just been updated for the latest version of 0.9.1.

Quick! Read it, before it breaks again!
(ah, the joys of 0.x languages ^^;)

If the book's a learning curve is too steep, I suggest reading the Haskellbook first, which is rather gentle and meticulous. I think it would also work to deepen your FP knowledge after the "By Example" book.

(I know, learning Haskell to learn Purescript is suboptimal, but don't know what else to tell you. Try the Purescript book first, anyway)

Purescript-elm project

I suggest you also take a look at purescript-elm, a project to reimplement both Elm 0.16 and 0.17 in purescript. With it you should be able to port your apps (if simple) just by porting the syntax.

Lots to learn from the author's talk at a past Purescript meetup, video is not up yet, but you can see the slides.

He's been reimplementing all of Elm, using as little javascript as possible, so you can see some Elm internals (which would be in Javascript) as they look in a functional language (Purescript).

Editors

There is support for:

  • Atom (looks rather good)
  • Emacs (which I'll dedicate a post to, later)
  • Sublime Text
  • Vim
  • more

check the wiki for more info.

Tools and websites

  • pursuit: a database in which you can look up functions by their type signature
  • try.purescript.org: try Purescript without installing it
  • psci: interactive REPL
  • pscid: a fast file watcher
  • pulp: the build tool
  • psvm-js: the version manager

Online meetups

A lovely habit of the Purescript community is to have online video meetups twice a month (with zoom.us, which is a great tool for this!).

Hopefully this will go on even if the community grows, as it is a great way to keep up with the community, and pick people's mind about stuff.

Open Source commitment

Purescript is an open source project, which people are encouraged to contribute to.

Elm is also an open source project, but Purescript is more committed to openness IMO.

Let's compare them on a few key points:

Public Roadmap

Elm: doesn't have one at the moment.

Purescript: has one of sorts, maintained through Github issues, mainly

Timely Deprecation Warnings

Purescript: deprecation is in place for at least a version, before removing the deprecated functionality.

Elm: in 0.17 the announcement of deprecated Signals/Mailboxes/etc was given on the mailing list as an alpha test release of 0.17, 2/3 weeks before the public release of 0.17

Complete Release Notes

Elm: has the tradition of using a blog post as release notes, which is nice, but I'd still like an itemised list of changes.
(If there is one, I couldn't find it just by looking at the website and at the github project.)

Purescript: has got itemised release notes, which live in an obvious place.

Contributing is encouraged

Elm: At the moment Elm doesn't have an infrastructure/process to accept people's contributions on many key repos.

Purescript: the community is smaller, but also less tightly controlled, so contributing is free and new ideas are listened to, both on the irc and on the online video meetup.

Conclusion

Elm: Mixing an "Apple product" approach with an open source project (secret before launch, tight-lipped on what's going to come) may be good for Evan's design creativity, but it's pretty inconsistent and inconvenient for people trying to set up Elm to use in production.
Surprises may, and do, happen.

Purescript: A tidily and responsively managed open source project, you can see what's coming, and you can influence it, too.

Chat

Freenode's #purescript is the place you should check first for help, then the gitter, and the subreddit.
Also the Functional Programming Slack has got a Purescript channel.

Twitter

If you use twitter, the community is fairly active. There is the #purescript hashtag and here's a few people to follow: Phil (author), Texas, Ryan (author of purescript-elm), kritzcreek (author of pscid), suppi aka gilmi.

Conclusion

That looks like enough to get you started, go learn some Purescript and have fun!

P.S. Special thanks to paf31, kritzcreek and suppi