Description #
PureScript is a strongly-typed, purely functional language that compiles to JavaScript, making it ideal for building robust front-end and back-end web applications. It offers Haskell-like syntax, powerful type inference, and safe functional programming in the JavaScript ecosystem.
History #
PureScript was created by Phil Freeman and released in 2013. It was developed to bring Haskell-style programming to JavaScript while focusing on simplicity and compatibility with modern tooling.
Key milestones:
- Inspired by Haskell but designed to generate clean JS
- Emphasizes type safety, purity, and expressiveness
- Frequently used with frameworks like Halogen and React
- Gained traction among functional programming enthusiasts building typed web apps
Hello World Code #
module Main where
import Effect.Console (log)
import Effect (Effect)
main :: Effect Unit
main = log "Hello, World!"
How to Run #
Online: #
- Use Try PureScript
- Paste the code and click Run
Locally: #
- Install PureScript:
npm install -g purescript spago
Create a new project:
spago init
Replace src/Main.purs
with the code above
Build and run:
spago run
Key Concepts #
main :: Effect Unit
— entry point with explicit side effect typelog
— prints to the console from theEffect.Console
module- Pure functions — no side effects unless declared
- Strong static types — prevents runtime errors
- Type inference — compiler often figures out types for you
- Algebraic data types — build complex but safe data models
- Module system — clean, dependency-aware organization
- Interop with JS — use and write JavaScript from PureScript
- Composable architecture — functional patterns for reusability
- Compiles to readable JavaScript — easy to debug and optimize
Try It Online #
🔗 Try PureScript
🔗 Replit – PureScript
🔗 PureScript Book Site
Fun Facts #
- PureScript was created to solve JavaScript complexity with Haskell-style safety
- Its generated JavaScript is often more readable than code from TypeScript
- PureScript supports FFI (foreign function interface) for integrating JS libraries
- PureScript developers often write fewer lines of code for the same logic
- Halogen, a PureScript UI framework, is one of the most type-safe UI libraries available