Cover image for "Haskell for the Front-End" :: Elm vs. PureScript

"Haskell for the Front-End" :: Elm vs. PureScript

awwsmm profile image Andrew (he/him) ・1 min read

Elm and PureScript are both strongly-typed, purely-functional, front-end programming languages.

They both compile to JavaScript, from what I've found online (they don't use WebAssembly).

PureScript seems to resemble Haskell a bit more than Elm, and offers some features that Elm doesn't have, like higher-kinded types.

Other than that, I can't see any other huge differences between the two languages.

Can anyone with experience in both of these languages speak to the differences between them? (Here's an old discussion related to this topic.)


Editor guide
wolfadex profile image
Wolfgang Schuster

Not my words, but copy pasted from Elm Slack:

"I dont have a dev.to account but:

PS can compile to JS, C++, Go, and (recently/?incompletely?) Erlang.

You can write TEA-style code in PS but you can't write all PS-style code in Elm. There's lots of webapp frameworks(React-wrappers, Pux(TEA), Halogen(VirtualDom), FRP-style, etc.) with different tradeoffs instead of being limited to Browser.element & friends.

PS doesn't force you to a global model or message - sub-units can store their own state & perform effects without having to wire them through all the parent units.

PS's FFI produces PS functions instead of async Cmds like Elm.

PS has typeclasses(Monads + do notation!), HKTs, explicit foralls, derivable/generic JSON encoding/decoding, etc.

While Elm simply has elm make, elm install, etc. PS has different tools you can use, bower for pkgs, pulpfor building,psc-packagefor package sets,spagofor building & package sets,pscid` for quick rebuilds/test-running, etc.

Elm has an implicit Prelude/Basics with much more to work w/ while PS makes you import Prelude and that doesn't even include the Either & Maybe types or constructors!

Elm has way more users.

Since Elm has only TEA, there's many more UI component libraries & they all work together. With PS you're limited to UI libraries that are structured for the framework you use.

You'll probably have to set up you're own routing flow in PS. In Elm you can just use Browser.

Elm enforces SemVar in package versions, PS doesn't.

Etc etc...

Here's some PS code I wrote:

And some Elm:

  • @lysergia
steshaw profile image
Steven Shaw

Given your experience with both Elm and PureScript, which do you prefer?

wolfadex profile image
Wolfgang Schuster

I don't have experience with PureScript, I was quoting someone from the Elm Slack who has used both but doesn't have a dev.to account.

Thread Thread
steshaw profile image
Steven Shaw

No worries, I missed that bit. You're enjoying Elm though? I seem to recall that it's a completely total language (with perhaps an escape hatch or two).

Thread Thread
wolfadex profile image
Wolfgang Schuster

I absolutely love Elm. It definitely has its flaws, but it's the friendliest language I've ever used. Not just for someone who's never programmes before, but also people with many years of experience. I've been doing front end development for 8 years now and if I could I'd only write Elm with a sprinkling of JS here and there.

I even spent 3 months writing up a proposal for work about why Elm was the best choice for a project we started back in June.

I think my favorite part is that the community and the language aren't about being the most concise or "the best". The focus is all about communication, both between the developer and the language, and between developers. Good communication, for me, is more valuable than almost anything else.

benjmhart profile image
Ben Hart

So, I can't speak to Elm as my experience is quite limited, however Elm's Language+Framework in One philosophy appears to bind it's domain quite strictly to front end development (Mainly SPA development)

However because of both it's language features and the development team's efforts to make great compiler messages, Elm has a reputation as being extremely beginner friendly and approachable.

Purescript, on the other hand, is more-or-less like writing haskell 2010, with a few type level adjustments which really make working in (and compiling to) the Browser or Node environment more bearable:

the biggest differences:
1) PureScript is strictly evaluated
2) PureScript uses Types that are encoded more similarly to those in Javascript. So where in Haskell we have String as a list and Text/ByteString, In PureScript we generally deal with JavaScript strings, Int and Float (Both of which are JavaScript Numbers), and we use Arrays as the default collection instead of linked lists.
3) PureScript has Anonymous Records and Row Types - essentially this allows for writing functions which depend on field names with a given type rather than requiring the function to operate on a specific type or typeclass.
4) PureScript typeclasses are more granular and better organized than Haskell since the creators are not tied to historical implementations

PureScript is not tied to a particular domain, you can write full-stack applications in PureScript.

I would say that other commenters recommending bower to get started with PureScript are using slightly outdated techniques, as it's much more common practive now to use the spago dependency manager & build tool.

there's a few operator differences and syntax querks, but largely you can write PureScript as if you were writing Haskell and get away with it.(Depending on how close to Haskell 2010 you normally write).

wolfadex profile image
Wolfgang Schuster

That's interesting about spago. I haven't looked at PureScript in months and was completely unaware. Definitely want to look at it more now!