PureScript

Last updated
PureScript
PureScript Logo.png
Paradigm Functional
Designed by Phil Freeman
First appeared2013
Stable release
0.15.15  OOjs UI icon edit-ltr-progressive.svg / 7 February 2024;2 months ago (7 February 2024)
Typing discipline Inferred, static, strong
License BSD [1]
Filename extensions .purs
Website www.purescript.org OOjs UI icon edit-ltr-progressive.svg
Influenced by
Haskell, JavaScript

PureScript is a strongly-typed, purely-functional programming language that transpiles to JavaScript, [2] C++11, [3] Erlang, [4] and Go. [5] It can be used to develop web applications, server side apps, and also desktop applications with use of Electron or via C++11 and Go compilers with suitable libraries. Its syntax is mostly comparable to that of Haskell. In addition, it introduces row polymorphism and extensible records. [6] Also, contrary to Haskell, the PureScript language is defined as having a strict evaluation strategy, [7] although there are non-conforming back ends which implement a lazy evaluation strategy. [8]

Contents

History

PureScript was initially designed by Phil Freeman in 2013. He started to work on PureScript since he wasn't satisfied by other attempts to transpile Haskell to JavaScript (e.g. using Fay, Haste, or GHCJS). [9]

Since then it has been picked up by the community and is developed on GitHub. Additional core tools developed by the community include the dedicated build tool "Pulp", [10] the documentation directory "Pursuit", [11] and the package manager "Spago" [12]

Features

PureScript features strict evaluation, persistent data structures and type inference. The PureScript type system shares many features with those of similar functional languages like Haskell: algebraic data types and pattern matching, higher kinded types, type classes and functional dependencies, and higher-rank polymorphism. PureScript's type system adds support for row polymorphism and extensible records. [13] However, PureScript lacks support for some of the more advanced features of Haskell like GADTs and type families.

The PureScript transpilers attempt to produce readable code, where possible. Through a simple FFI interface, it also allows the reuse of existing JavaScript [14] /C++11 [15] [16] /Go [17] code.

PureScript supports incremental compilation, and the transpiler to JavaScript distribution includes support for building source code editor plugins for iterative development. [18] Editor plugins exist for many popular text editors, including Vim, Emacs, Sublime Text, Atom and Visual Studio Code.

PureScript supports type-driven development via its typed holes feature, [19] in which a program can be constructed with missing subexpressions. The JavaScript transpiler will subsequently attempt to infer the types of the missing subexpressions, and report those types to the user. This feature has inspired similar work in the GHC Haskell compiler. [20]

Examples

Here is a minimal "Hello world" program in PureScript:

moduleMainwhereimportEffect.Console(log)main=log"Hello World!"

Here, the type of the program is inferred and checked by the PureScript transpiler. A more verbose version of the same program might include explicit type annotations:

moduleMainwhereimportPreludeimportEffect(Effect)importEffect.Console(log)main::EffectUnitmain=log"Hello World!"

See also

Related Research Articles

<span class="mw-page-title-main">Java virtual machine</span> Virtual machine that runs Java programs

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

ECMAScript is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is standardized by Ecma International in the document ECMA-262.

Programming languages can be grouped by the number and types of paradigms supported.

<span class="mw-page-title-main">Scala (programming language)</span> General-purpose programming language

Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are intended to address criticisms of Java.

TypeScript is a free and open-source high-level programming language developed by Microsoft that adds static typing with optional type annotations to JavaScript. It is designed for the development of large applications and transpiles to JavaScript. Because TypeScript is a superset of JavaScript, all JavaScript programs are syntactically valid TypeScript, but they can fail to type-check for safety reasons.

QuickCheck is a software library, specifically a combinator library, originally written in the programming language Haskell, designed to assist in software testing by generating test cases for test suites – an approach known as property testing.

Svelte is a free and open-source component-based front-end software framework, and language created by Rich Harris and maintained by the Svelte core team members.

<span class="mw-page-title-main">Clojure</span> Dialect of the Lisp programming language on the Java platform

Clojure is a dynamic and functional dialect of the Lisp programming language on the Java platform.

<span class="mw-page-title-main">Google Closure Tools</span> JavaScript developer toolkit

Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. As of 2023, the project had over 230K LOCs not counting the embedded Mozilla Rhino compiler.

<span class="mw-page-title-main">Node.js</span> JavaScript runtime environment

Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more. Node.js runs on the V8 JavaScript engine, and executes JavaScript code outside a web browser.

Haskell is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell has pioneered a number of programming language features such as type classes, which enable type-safe operator overloading, and monadic input/output (IO). It is named after logician Haskell Curry. Haskell's main implementation is the Glasgow Haskell Compiler (GHC).

Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google. It can be used to develop web and mobile apps as well as server and desktop applications.

<span class="mw-page-title-main">Elm (programming language)</span> Functional programming language

Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness. It advertises "no runtime exceptions in practice", made possible by the Elm compiler's static type checking.

Idris is a purely-functional programming language with dependent types, optional lazy evaluation, and features such as a totality checker. Idris may be used as a proof assistant, but is designed to be a general-purpose programming language similar to Haskell.

<span class="mw-page-title-main">Nim (programming language)</span> Programming language

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level systems programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

<span class="mw-page-title-main">Reason (programming language)</span> Syntax extension and toolchain for OCaml

Reason, also known as ReasonML, is a syntax extension and toolchain for OCaml created by Jordan Walke, who also created the React framework, at Facebook. Reason offers a syntax familiar to JavaScript programmers, and compiles to native code using OCaml's compiler toolchain. Reason code may also be compiled to JavaScript using the ReScript compiler.

<span class="mw-page-title-main">Deno (software)</span> Secure JavaScript and TypeScript runtime

Deno is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. Deno was co-created by Ryan Dahl, who also created Node.js.

References

  1. "purescript/purescript". GitHub. 3 June 2022.
  2. "PureScript to JavaScript transpiler". GitHub . Retrieved 2023-01-22.
  3. "PureScript to C++11 transpiler". GitHub . Retrieved 2023-01-22.
  4. purerl - the PureScript Erlang backend, purerl, 2023-09-04, retrieved 2023-09-05
  5. "PureScript to Go transpiler". GitHub . Retrieved 2023-01-22.
  6. "PureScript". purescript.org. Retrieved 2019-03-14.
  7. purescript/documentation, PureScript, 2023-02-19, retrieved 2023-02-20
  8. Alternative backends, PureScript, 2023-02-19, retrieved 2023-02-20
  9. "Read PureScript by Example | Leanpub". leanpub.com. Retrieved 2019-03-14.
  10. A build tool for PureScript projects, PureScript Contrib, 2019-03-08, retrieved 2019-03-14
  11. "Pursuit". pursuit.purescript.org. Retrieved 2019-03-14.
  12. 🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago, spacchetti, 2019-03-14, retrieved 2019-03-14
  13. Documentation for the PureScript language, compiler, and tools.: purescript/documentation, PureScript, 2019-03-14, retrieved 2019-03-14
  14. "The Foreign Function Interface". PureScript. 2015-07-15. Retrieved 2023-01-22.
  15. "FFI". PureScript. 2019-07-26. Retrieved 2023-01-22.
  16. C++ foreign export implementations for the standard library, PureScript, 2019-07-26, retrieved 2023-01-22
  17. "Go foreign export implementations for the standard library". PureScript. 2020-12-13. Retrieved 2023-01-22.
  18. purs ide: Editor and tooling support for the PureScript programming language, 2019-04-21, retrieved 2019-04-21
  19. Implementing type directed search for PureScript, 2016-10-27
  20. Matthías Páll Gissurarson (2018-09-27), "Suggesting Valid Hole Fits for Typed-Holes (Experience Report)", ACM SIGPLAN Notices, 53 (7): 179–185, doi:10.1145/3299711.3242760, S2CID   218480974