Untrusted input from external API
Languages / Knowledge library
PureScript
functional types and effects compiled to javascript
Why learn PureScript?
Useful for typed functional programs in JavaScript environments. Foreign-function boundaries must accurately describe the JavaScript values they expose.
Where it came from
PureScript is a strongly typed functional language that compiles to JavaScript. Its features include algebraic data types, type classes, and extensible records.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Define a sum type and exhaustive match.
- Transform a collection with pure functions.
- Separate an effectful action from pure logic.
- Bind a small JavaScript function.
- Test the assumptions in the foreign-function interface.
Documentation and sources
- Official project documentation (www.purescript.org)
Catalog research notes
- Research snapshot: September 9, 2026. This entry summarizes the linked primary documentation; it does not assert a latest release version.
Connect the ideas
Explore next
Real World Example
Type-Safe Financial Ledger Integration
A boutique fintech firm managing cross-border currency conversions.
The business problem
Runtime errors in JavaScript-based transaction processing logic frequently cause silent failures when handling unexpected currency record formats, leading to reconciliation discrepancies.
How this topic solves it
PureScript provides algebraic data types and row polymorphism to strictly define transaction schemas, ensuring that any missing or malformed data in a ledger record is caught at compile-time rather than during execution.
- Define a sum type for Currency using algebraic data types to restrict valid inputs.
- Implement a record type with row polymorphism to represent flexible ledger entries.
- Write pure transformation functions that map incoming JSON to the validated record types.
- Use the Effect monad to handle the side-effecting process of writing validated records to the database.
- Compile the PureScript modules into clean JavaScript for integration with existing Node.js services.
This flow illustrates how raw data is processed through PureScript's type system before reaching the database.
Uses algebraic data types to validate structure
Strictly typed internal representation
Persistent storage for ledger entries
- Raw JSON → Input → PureScript Parser
- PureScript Parser → Type-checked transformation → Validated Record
- Validated Record → Effectful write → Database
Implementation example
This code demonstrates how algebraic data types and records enforce structure on financial data before any side effects occur.
data Currency = USD | EUR | GBP -- Algebraic data type for strict currency control
type LedgerEntry = { amount :: Number, currency :: Currency } -- Row polymorphism for record structure
processEntry :: LedgerEntry -> String
processEntry entry = "Processed " <> show entry.amount -- Pure function ensures data is valid before processingExpected business outcome
The system achieves structural integrity where the application logic cannot proceed unless the transaction data strictly conforms to the defined financial schema, significantly reducing runtime exceptions.
Limitations and checks
The primary limitation is the increased cognitive load and compilation overhead associated with strict type checking; developers can verify this by monitoring the time taken for the Spago build tool to perform type inference on large, deeply nested record structures.