PureScript
Paradigm | Functional |
---|---|
Designed by | Phil Freeman |
First appeared | 2013 |
Stable release | 0.15.12
/ October 7, 2023 |
Typing discipline | Inferred, static, strong |
License | BSD[1] |
Filename extensions | .purs |
Website | {{{1}}} |
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]
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:
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 Unit main = log "Hello World!"
See also
- Elm (programming language) – Functional programming language
- Reason (programming language) – Syntax extension and toolchain for OCaml
- JS++ – Web programming language
- TypeScript – Programming language and superset of JavaScript
References
- ↑ "purescript/purescript". 3 June 2022. https://github.com/purescript/purescript/blob/master/LICENSE.
- ↑ "PureScript to JavaScript transpiler". https://github.com/purescript/purescript.
- ↑ "PureScript to C++11 transpiler". https://github.com/andyarvanitis/purescript-native/tree/cpp.
- ↑ purerl - the PureScript Erlang backend, purerl, 2023-09-04, https://github.com/purerl/purerl, retrieved 2023-09-05
- ↑ "PureScript to Go transpiler". https://github.com/andyarvanitis/purescript-native.
- ↑ "PureScript". https://purescript.org/.
- ↑ purescript/documentation, PureScript, 2023-02-19, https://github.com/purescript/documentation/blob/ddc83562aa1de9d4e2c1067c71bf3d4e3b77b84d/language/Differences-from-Haskell.md, retrieved 2023-02-20
- ↑ Alternative backends, PureScript, 2023-02-19, https://github.com/purescript/documentation/blob/ddc83562aa1de9d4e2c1067c71bf3d4e3b77b84d/ecosystem/Alternate-backends.md, retrieved 2023-02-20
- ↑ "Read PureScript by Example | Leanpub". https://leanpub.com/purescript/read#leanpub-auto-about-the-author.
- ↑ A build tool for PureScript projects, PureScript Contrib, 2019-03-08, https://github.com/purescript-contrib/pulp, retrieved 2019-03-14
- ↑ "Pursuit". https://pursuit.purescript.org/.
- ↑ 🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago, spacchetti, 2019-03-14, https://github.com/spacchetti/spago, retrieved 2019-03-14
- ↑ Documentation for the PureScript language, compiler, and tools.: purescript/documentation, PureScript, 2019-03-14, https://github.com/purescript/documentation, retrieved 2019-03-14
- ↑ "The Foreign Function Interface". PureScript. 2015-07-15. https://github.com/purescript/documentation/blob/master/guides/FFI.md.
- ↑ "FFI". PureScript. 2019-07-26. https://github.com/andyarvanitis/purescript-native/wiki/FFI.
- ↑ C++ foreign export implementations for the standard library, PureScript, 2019-07-26, https://github.com/andyarvanitis/purescript-native-cpp-ffi, retrieved 2023-01-22
- ↑ "Go foreign export implementations for the standard library". PureScript. 2020-12-13. https://github.com/andyarvanitis/purescript-native-go-ffi.
- ↑ purs ide: Editor and tooling support for the PureScript programming language, 2019-04-21, https://github.com/purescript/purescript/tree/dfbd19da85c92d82ed4c3184f950f74da5332e3f/psc-ide, retrieved 2019-04-21
- ↑ Implementing type directed search for PureScript, 2016-10-27
- ↑ 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, https://dl.acm.org/citation.cfm?id=3242760
External links
Original source: https://en.wikipedia.org/wiki/PureScript.
Read more |