Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 12, 2026·3 min de lectura

PureScript — Strongly-Typed Functional Language Compiling to JavaScript

PureScript is a strongly-typed, purely functional programming language that compiles to readable JavaScript, offering Haskell-inspired syntax with a practical focus on web and Node.js development.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
PureScript
Comando de instalación directa
npx -y tokrepo@latest install c82823fa-7def-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

PureScript is a purely functional programming language with a powerful type system that compiles to clean, readable JavaScript. Inspired by Haskell, it brings algebraic data types, type classes, higher-kinded types, and row polymorphism to the JavaScript ecosystem while producing output that integrates naturally with existing JS libraries.

What PureScript Does

  • Compiles to human-readable JavaScript or alternative backends (Erlang, Go, C++)
  • Provides a sound type system with full type inference and no runtime type errors
  • Supports algebraic data types, pattern matching, and type classes for expressive abstractions
  • Offers row polymorphism for flexible, type-safe records and effects
  • Interoperates with existing JavaScript code through a foreign function interface

Architecture Overview

The PureScript compiler is written in Haskell and translates source files into CommonJS or ES modules. It performs full type checking and inference before code generation, catching entire classes of errors at compile time. The Spago package manager handles dependency resolution from the PureScript package registry. The effect system tracks side effects in types, making pure and impure code explicitly separated.

Self-Hosting & Configuration

  • Install via npm: npm install -g purescript spago for compiler and package manager
  • Use spago init to scaffold a project with spago.yaml for dependency configuration
  • Configure the output directory and backend in spago.yaml under the package section
  • Set up IDE support with the PureScript language server for VS Code or other editors
  • Use spago bundle-app to produce a single JavaScript file for browser deployment

Key Features

  • Sound type system guarantees no runtime type errors in PureScript code
  • Row polymorphism enables extensible records and variant types without boilerplate
  • Effect system (via the Eff or Aff monad) makes side effects explicit and composable
  • Clean JavaScript output that is readable and debuggable without source maps
  • Comprehensive standard library with Halogen and React bindings for web UIs

Comparison with Similar Tools

  • Haskell — PureScript shares syntax and concepts but targets JavaScript instead of native code, with a simpler build story for web projects
  • Elm — Simpler type system focused on web UIs; PureScript offers higher-kinded types and more flexibility at the cost of a steeper learning curve
  • TypeScript — Gradual typing over JavaScript; PureScript provides full type safety with no escape hatches
  • ReScript — ML-family language for JS with faster compilation; PureScript offers a richer type system with type classes
  • ClojureScript — Dynamic functional language for JS; PureScript catches errors at compile time through static typing

FAQ

Q: Can PureScript use existing npm packages? A: Yes. PureScript provides a Foreign Function Interface (FFI) that lets you wrap any JavaScript module with PureScript type signatures for safe interop.

Q: What is Spago? A: Spago is the official PureScript package manager and build tool. It manages dependencies from the PureScript registry, handles builds, and can bundle output for browsers.

Q: Is PureScript suitable for production use? A: Yes. Companies use PureScript in production for web applications, internal tools, and backend services. The type system catches bugs at compile time, reducing runtime failures.

Q: How does PureScript handle side effects? A: All side effects are tracked in the type system using monads like Effect (synchronous) and Aff (asynchronous). Pure functions cannot perform side effects, enforced by the compiler.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados