Thursday, October 22, 2020

Elm vs. PureScript

I'm convinced one of them (or something similar) will be the future, but it's too soon to say for sure. The Elm community is growing crazy fast and it's really focused on being beginner-friendly and having a good dev experience (see this recent talk from Elm's creator: https://www.youtube.com/watch?v=oYk8CKH7OhE). This focus has kept the language simple and lots of work has been done on making the compiler errors helpful and instructive. Elm also limits communication with JS to an interface called 'ports', basically just message passing that both sides must parse and act on. Elm also has focused pretty exclusively on coding client-side UIs (i.e. the Angular or Ember or (most similarly) React+Redux space)

PureScript is a similar idea (a statically typed functional language compiling to JS), but with a different background and different short-term goals. PureScript modules compile to CommonJS modules. PureScript functions compile to JS functions. The FFI (talking to JS code) is more like TypeScript or Flow, where you define the foreign types in a PureScript file and tell the compiler to trust you (rather than passing strings through a 'port')

This makes FFI easier and faster, but also more dangerous.

PureScript also aims to produce readable JS, so it can be used and understood without souremaps if necessary. It also doesn't have a runtime, like Elm, resulting in smaller, more flexible output (you can target browsers, cli apps, node, aws lambda, etc)

PureScript also has a more complete type system, in some ways more modern than Haskell's. It makes it less approachable for people with no Haskell experience, but allows more powerful abstraction than Elm provides

This is an intro to PureScript and its JS output from a recent meetup I presented at: https://www.youtube.com/watch?v=9a57V3bvzaI

A little example to highlight that difference (Elm is currently a UI building language, PureScript is just a different way to write JS) is that currently both the Elm and PureScript compilers are written in Haskell, and the PureScript build tool, Pulp, is written in JS. But both PureScript itself and Pulp are in the middle of being rewritten in PureScript. I don't know of any plans to do that with Elm in the near future. The PureScript compiler is also being built with compiling to multiple backends in mind (JS, LLVM, maybe Lua)

Elm will slowly adopt things from PureScript and vice versa. Either Elm will be a stepping stone or learning platform to eventually jump to PureScript, or PureScript will prove too steep a learning curve for most people's needs and it'll become niche or die out. In the meantime, the competition will improve both languages : ]



from Hacker News https://ift.tt/2edRbxY

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.