Top Related Projects
Compiler for Elm, a functional language for reliable webapps.
A purely functional programming language with first class types
Agda is a dependently typed programming language / interactive theorem prover.
The core OCaml system: compilers, runtime system, base libraries
Mirror of the Glasgow Haskell Compiler. Please submit issues and patches to GHC's Gitlab instance (https://gitlab.haskell.org/ghc/ghc). First time contributors are encouraged to get started with the newcomers info (https://gitlab.haskell.org/ghc/ghc/wikis/contributing).
Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
Quick Overview
PureScript is a strongly-typed functional programming language that compiles to JavaScript. It's inspired by Haskell and aims to provide a robust type system, excellent tooling, and seamless interoperability with existing JavaScript code.
Pros
- Strong static typing helps catch errors at compile-time
- Powerful type inference reduces the need for explicit type annotations
- Excellent JavaScript interoperability
- Active community and growing ecosystem
Cons
- Steeper learning curve for developers not familiar with functional programming
- Smaller ecosystem compared to more established languages
- Compile times can be slow for large projects
- Limited resources and learning materials compared to mainstream languages
Code Examples
- Hello World example:
module Main where
import Effect.Console (log)
main = log "Hello, World!"
- Simple function definition and usage:
module Example where
import Prelude
double :: Int -> Int
double x = x * 2
result :: Int
result = double 5 -- result is 10
- Working with Maybe type:
module MaybeExample where
import Prelude
import Data.Maybe (Maybe(..), fromMaybe)
safeDivide :: Int -> Int -> Maybe Int
safeDivide _ 0 = Nothing
safeDivide a b = Just (a / b)
result :: Int
result = fromMaybe 0 (safeDivide 10 2) -- result is 5
Getting Started
- Install PureScript and its build tool:
npm install -g purescript spago
- Create a new project:
mkdir my-project
cd my-project
spago init
- Add your code to
src/Main.purs
and run:
spago run
For more detailed instructions, visit the official PureScript documentation at https://www.purescript.org/
Competitor Comparisons
Compiler for Elm, a functional language for reliable webapps.
Pros of Elm compiler
- Simpler language with a gentler learning curve
- Strong focus on developer experience and friendly error messages
- Enforces a more opinionated architecture, leading to consistent codebases
Cons of Elm compiler
- Less flexible and expressive compared to PureScript
- Smaller ecosystem with fewer libraries and tools
- Limited interoperability with JavaScript
Code comparison
Elm:
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
main =
Browser.sandbox { init = 0, update = update, view = view }
update msg model =
case msg of
Increment -> model + 1
Decrement -> model - 1
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Increment ] [ text "+" ]
]
PureScript:
module Main where
import Prelude
import Effect (Effect)
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
data Action = Increment | Decrement
component :: forall q i o m. H.Component q i o m
component =
H.mkComponent
{ initialState: const 0
, render
, eval: H.mkEval $ H.defaultEval { handleAction = handleAction }
}
render :: forall m. Int -> H.ComponentHTML Action () m
render state =
HH.div_
[ HH.button [ HE.onClick \_ -> Decrement ] [ HH.text "-" ]
, HH.div_ [ HH.text $ show state ]
, HH.button [ HE.onClick \_ -> Increment ] [ HH.text "+" ]
]
handleAction :: forall o m. Action -> H.HalogenM Int Action () o m Unit
handleAction = case _ of
Increment -> H.modify_ (_ + 1)
Decrement -> H.modify_ (_ - 1)
A purely functional programming language with first class types
Pros of Idris2
- Dependent types allow for more expressive and precise type-level programming
- Totality checking ensures all functions terminate, improving program correctness
- Supports interactive theorem proving, enabling formal verification of code
Cons of Idris2
- Smaller community and ecosystem compared to PureScript
- Steeper learning curve due to advanced type system features
- Potentially slower compilation times for complex dependent type programs
Code Comparison
Idris2:
factorial : Nat -> Nat
factorial 0 = 1
factorial n = n * factorial (n - 1)
-- Proof that factorial is always positive
factorialPositive : (n : Nat) -> LT 0 (factorial n)
factorialPositive 0 = LTESucc LTEZero
factorialPositive (S k) = LTESucc (multLTELeft (S k) (factorial k) (factorialPositive k))
PureScript:
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)
-- No built-in support for theorem proving
-- Type-level programming is possible but less expressive
The code comparison showcases Idris2's ability to include proofs within the code, demonstrating its dependent type system and theorem-proving capabilities. PureScript, while powerful, lacks these advanced features but offers a more familiar and approachable syntax for functional programming.
Agda is a dependently typed programming language / interactive theorem prover.
Pros of Agda
- More powerful type system with dependent types
- Stronger focus on theorem proving and formal verification
- Closer integration with mathematical concepts and proofs
Cons of Agda
- Steeper learning curve and more complex syntax
- Smaller ecosystem and fewer libraries
- Less focus on practical application development
Code Comparison
Agda:
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
head : ∀ {A n} → Vec A (suc n) → A
head (x ∷ _) = x
PureScript:
data Vec a = Nil | Cons a (Vec a)
head :: forall a. Vec a -> Maybe a
head Nil = Nothing
head (Cons x _) = Just x
The Agda example showcases its dependent types, allowing for precise length specification in the vector type. PureScript's version is simpler but less type-safe, using Maybe for potential empty vectors.
Agda excels in formal verification and theorem proving, while PureScript is more suited for practical functional programming in web development. Agda's type system is more expressive but comes with increased complexity, whereas PureScript offers a balance between strong typing and ease of use.
The core OCaml system: compilers, runtime system, base libraries
Pros of OCaml
- Mature ecosystem with a long history and extensive standard library
- Strong support for systems programming and native code compilation
- Powerful module system for large-scale software engineering
Cons of OCaml
- Steeper learning curve, especially for developers new to functional programming
- Less focus on web development and JavaScript interoperability
- Smaller community compared to more mainstream languages
Code Comparison
OCaml:
let rec factorial n =
if n = 0 then 1
else n * factorial (n - 1)
let result = factorial 5
PureScript:
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)
result = factorial 5
Summary
OCaml is a mature, statically-typed functional language with a focus on systems programming and native compilation. It offers a powerful module system and extensive standard library. PureScript, on the other hand, is designed for web development with JavaScript interoperability in mind. It has a more approachable syntax for developers coming from JavaScript backgrounds.
While OCaml excels in systems programming and large-scale software engineering, PureScript shines in web development scenarios. OCaml has a steeper learning curve but offers more low-level control, whereas PureScript provides a gentler introduction to functional programming for web developers.
Both languages share similar functional programming concepts, as seen in the factorial example, but differ in their syntax and ecosystem focus.
Mirror of the Glasgow Haskell Compiler. Please submit issues and patches to GHC's Gitlab instance (https://gitlab.haskell.org/ghc/ghc). First time contributors are encouraged to get started with the newcomers info (https://gitlab.haskell.org/ghc/ghc/wikis/contributing).
Pros of GHC
- Mature and widely-used compiler for Haskell, with extensive ecosystem support
- Highly optimized runtime system for efficient execution of Haskell programs
- Supports a broader range of language extensions and features
Cons of GHC
- Larger codebase and more complex architecture, making it harder to contribute
- Slower compilation times, especially for large projects
- Steeper learning curve for newcomers to the Haskell ecosystem
Code Comparison
PureScript (simplified example):
module Main where
import Effect.Console (log)
main :: Effect Unit
main = log "Hello, PureScript!"
GHC Haskell (simplified example):
module Main where
main :: IO ()
main = putStrLn "Hello, Haskell!"
Summary
GHC is a more established and feature-rich compiler for Haskell, offering advanced optimizations and a wide range of language extensions. However, it comes with increased complexity and longer compilation times. PureScript, while younger and less feature-rich, offers a more approachable system with faster compilation and a focus on JavaScript interoperability. The code examples demonstrate the similarity in syntax between the two languages, with PureScript's additional type annotations for effects.
Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
Pros of Reason
- Easier learning curve for developers familiar with JavaScript
- Better integration with existing JavaScript ecosystems and tooling
- Faster compilation times for large projects
Cons of Reason
- Smaller community and ecosystem compared to PureScript
- Less emphasis on advanced functional programming concepts
- More limited type system compared to PureScript's expressive types
Code Comparison
Reason:
let add = (a, b) => a + b;
let result = add(5, 3);
Js.log("Result: " ++ string_of_int(result));
PureScript:
add :: Int -> Int -> Int
add a b = a + b
main :: Effect Unit
main = do
let result = add 5 3
log $ "Result: " <> show result
Both languages aim to provide a statically-typed functional programming experience for web development. Reason focuses on accessibility and JavaScript interoperability, while PureScript emphasizes purity and advanced type system features. Reason may be more appealing to developers transitioning from JavaScript, while PureScript might attract those seeking a more rigorous functional programming experience.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME

A small strongly typed programming language with expressive types that compiles to JavaScript, written in and inspired by Haskell.
Language info
Resources
Help!
Community Spaces
The following spaces are governed by the PureScript Community Code of Conduct. The majority of PureScript users use these spaces to discuss and collaborate on PureScript-related topics:
Unaffiliated Spaces
Some PureScript users also collaborate in the below spaces. These do not fall under the code of conduct linked above. They may have no code of conduct or one very different than the one linked above.
Top Related Projects
Compiler for Elm, a functional language for reliable webapps.
A purely functional programming language with first class types
Agda is a dependently typed programming language / interactive theorem prover.
The core OCaml system: compilers, runtime system, base libraries
Mirror of the Glasgow Haskell Compiler. Please submit issues and patches to GHC's Gitlab instance (https://gitlab.haskell.org/ghc/ghc). First time contributors are encouraged to get started with the newcomers info (https://gitlab.haskell.org/ghc/ghc/wikis/contributing).
Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot