PROVIDER - a strongly typed functional language compiled to JavaScript
PureScript
PureScript was created by Phil Freeman in 2013 with Haskell-like syntax compiled to JavaScript, using type classes and row types to stop errors at compile time, and 1 FFI declaration to bind an existing JS library; conceptual depth, output size and a small community are the cost.
Detailed Notes
Pros 5 items
Cons 4 items
Service Overview
PureScript was created by Phil Freeman in 2013 as a strongly typed purely functional language that compiles to JavaScript. Its syntax and philosophy follow Haskell, with some heavyweight features dropped and the JavaScript runtime in mind.
In the languages and frameworks category it takes the maximal route on frontend typing: more annotations in exchange for catching errors before they ship.
Key Strengths
- Expressive type system: type classes, row types and higher-rank polymorphism cover sophisticated abstractions
- Compile-time safety: effects are marked with
Effect, so pure functions cannot leak side effects - Concise FFI: 1 declaration per foreign function is enough to bind it
- No runtime dependency: output is plain JavaScript that drops into an existing build chain
- Reproducible dependencies: package sets pin whole versions so team environments match
Product Ecosystem
Language and compiler
The PureScript compiler, the spago build tool and the Pursuit documentation site form the base toolchain.
Frameworks and libraries
Halogen supplies a UI component model, purescript-aff handles asynchrony, and purescript-foreign covers decoding.
Tooling
purs-tidy formats code, and editors get completion and type hints through a language server.
Limitations
- Conceptual barrier: type classes and monads need systematic study
- Build cost: compile time and bundle size exceed TypeScript
- Scarce talent: the community is small, making hiring and handover harder
- Setup complexity: FFI, bundling and editor integration need extra work
Use Cases
- Frontends with complex business rules (★★★★): type constraints cut regression defects sharply
- Finance and data-dense interfaces (★★★★): numeric and state modelling pays off
- Teams already functional (★★★★): the frontend shares one type mindset with the back end
- Rapid prototypes and small pages (★★): TypeScript is faster
Pricing
| Item | Price | Notes |
|---|---|---|
| PureScript compiler | $0 | Open source, installed from npm or binaries |
| spago and package sets | $0 | Free to use |
| Learning material | From $0 | Official docs are free, books and courses are optional |
Language and tools are free; the cost is the team learning curve and build time.
FAQ
- PureScript or TypeScript? Choose PureScript for maximal type guarantees and purely functional style, and TypeScript for ecosystem reach and hiring supply.
- Does it work with React? Yes, either through FFI wrappers or by using Halogen instead; bindings such as
react-basicalso exist. - Why is the output large? The runtime library and type class dictionaries add code, which dead-code elimination and bundlers compress. See the comparison under languages and frameworks.
Code Examples
Summing through a type class
module Main where
import Prelude
import Data.Foldable (sum)
total :: Array Int -> Int
total xs = sum xs
main :: Effect Unit
main = logShow (total [1, 2, 3, 4])
sum relies on the Additive type class, Array Int satisfies it, and Effect Unit marks main as effectful.
Row types describing records
type User = { id :: Int, name :: String }
greet :: forall r. { name :: String | r } -> String
greet user = "Hello, " <> user.name
sample :: String
sample = greet { id = 1, name = "Ada", admin = true }
{ name :: String | r } accepts any record containing a name field, so extra fields do not break the call.
Community & Resources
- PureScript: documentation, examples and downloads
- GitHub PureScript topic: open libraries and frameworks
- GitHub Haskell topic: the source of the syntax and type ideas
- GitHub Elm topic: another functional frontend route
- GitHub TypeScript topic: the mainstream typed frontend comparison