PureScript explained

PureScript
Paradigm:Functional
Year:2013
Influenced By:Haskell, JavaScript
Typing:Inferred, static, strong
Designer:Phil Freeman
License:BSD[1]
File Ext:.purs

PureScript is a strongly-typed, purely-functional programming language that transpiles to JavaScript,[2] C++11,[3] Erlang, and Go.[4] 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.[5] Also, contrary to Haskell, the PureScript language is defined as having a strict evaluation strategy, although there are non-conforming back ends which implement a lazy evaluation strategy.

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).[6]

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", the documentation directory "Pursuit",[7] and the package manager "Spago"

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. 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[8] /C++11[9] /Go[10] code.

PureScript supports incremental compilation, and the transpiler to JavaScript distribution includes support for building source code editor plugins for iterative development. 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, 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.

Examples

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

module Main where

import Effect.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:

module Main where

import Prelude

import Effect (Effect)import Effect.Console (log)

main :: Effect Unitmain = log "Hello World!"

External links

Notes and References

  1. Web site: purescript/purescript. GitHub. 3 June 2022 .
  2. Web site: PureScript to JavaScript transpiler . . 2023-01-22.
  3. Web site: PureScript to C++11 transpiler . . 2023-01-22.
  4. Web site: PureScript to Go transpiler . . 2023-01-22.
  5. Web site: PureScript. purescript.org. 2019-03-14.
  6. Web site: Read PureScript by Example Leanpub. leanpub.com. 2019-03-14.
  7. Web site: Pursuit. pursuit.purescript.org. 2019-03-14.
  8. Web site: The Foreign Function Interface . 2015-07-15 . PureScript . 2023-01-22.
  9. Web site: FFI . 2019-07-26 . PureScript . 2023-01-22.
  10. Web site: Go foreign export implementations for the standard library . 2020-12-13 . PureScript . 2023-01-22.