So, you heard about PureScript and are wondering what it is? Well, you’re in luck, because today I am going to explain exactly what PureScript is, why it was created, where it’s used, how to learn PureScript, and more!
Let’s get right to it.
// Hello World Program In PureScript module Main where import Prelude import Effect (Effect) import Effect.Console (log) main :: Effect Unit main = do log "Hello PureScript!"
What Is PureScript?
As you can see, PureScript is pretty… Haskell-y:
import Prelude (($), (*), (==), bind, pure) import Data.Array ((..)) import Data.Tuple (Tuple(..)) import Control.Alternative (guard) factors :: Int -> Array (Tuple Int Int) factors n = do a <- 1 .. n b <- 1 .. a guard $ a * b == n pure $ Tuple a b
If you have never written in a functional programming language this code probably looks very foreign to you. Well, that’s because functional programming languages do things in a very different, and sometimes better way than traditional object oriented languages.
In fact, there is a pretty heated debate over what is better.
Why Was PureScript Created?
If you’ve followed my blog at all you may be aware that I am a big fan of functional programming languages. Functions as true first-class values, composability, immutability, expression based control flow just to name a few reasons why I wish functional programming was more common in the workplace.
This means that with PureScript you have a:
- built in build tool
- no linting required
- removes the ‘==’ and ‘===’ issue
- removes the outdated ‘var’ keyword
- removes the confusing ‘this’ keyword
- updated futures and promises and removes callback hell
- fully functional
- built in validation
- built in types
- built in pure functions
- built in immutable data
Sounds pretty great right? Well, that’s what the creators of PureScript thought too, and thus, PureScript was born!
Who Uses PureScript?
So, who is actually using PureScript then? Well, it doesn’t seem like a lot of people are actually using PureScript in 2022. There was a recent survey sent out to the PureScript discourse forum and chatroom. A total of 660 people responded to the survey and of that total, 43.6% were non-PureScripters. A pretty high number for a PureScript message forum! Additionally only 26.42% currently used PureScript at the time of taking the survey. You can see the full survey here.
Is PureScript Used In Production?
As you can see from this number, the number of PureScript users in generally is pretty low. Meaning that the amount of production level code would be even lower. However, there are some companies writing production code with PureScript.
In the 2019 Typelevel Summit, Felix Mulder talks about his experience how the Scala team transitioned into writing production code using PureScript in AWS lambda, and services using Haskell. You can watch the video here.
Where To Learn PureScript?
If you want to learn PureScript, a great place to start would be the docs. You could also utilize the discourse forums in order to ask questions and potentially find a mentor for your PureScript journey!
As always, happy coding!