PureScript
![]() | |
Paradigm | Functional |
---|---|
Designed by | Phil Freeman |
First appeared | 2013 |
Stable release | |
Typing discipline | Inferred,static,strong |
License | BSD[1] |
Filename extensions | .purs |
Website | www |
Influenced by | |
Haskell,JavaScript |
PureScriptis astrongly-typed,purely-functionalprogramming languagethattranspilestoJavaScript,[2]C++11,[3]Erlang,[4]andGo.[5]It can be used to develop web applications, server side apps, and also desktop applications with use ofElectronor via C++11 and Go compilers with suitable libraries. Its syntax is mostly comparable to that ofHaskell.In addition, it introducesrow polymorphismandextensible records.[6]Also, contrary to Haskell, the PureScript language is defined as having astrict evaluation strategy,[7]although there are non-conforming back ends which implement alazy evaluation strategy.[8]
History
[edit]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 onGitHub.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
[edit]PureScript featuresstrict evaluation,persistent data structuresandtype inference.The PureScript type system shares many features with those of similar functional languages likeHaskell:algebraic data typesandpattern matching,higher kinded types,type classesandfunctional dependencies,andhigher-rank polymorphism.PureScript's type system adds support forrow polymorphismand extensible records.[13]However, PureScript lacks support for some of the more advanced features of Haskell likeGADTsandtype families.
The PureScript transpilers attempt to produce readable code, where possible. Through a simpleFFI interface,it also allows the reuse of existing JavaScript[14]/C++11[15][16]/Go[17]code.
PureScript supportsincremental compilation,and the transpiler to JavaScript distribution includes support for buildingsource code editorplugins for iterative development.[18]Editor plugins exist for many popular text editors, includingVim,Emacs,Sublime Text,AtomandVisual Studio Code.
PureScript supportstype-driven developmentvia itstyped holesfeature,[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 theGHCHaskellcompiler.[20]
Examples
[edit]Here is a minimal"Hello world" programin PureScript:
moduleMainwhere
importEffect.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:
moduleMainwhere
importPrelude
importEffect(Effect)
importEffect.Console(log)
main::EffectUnit
main=log"Hello World!"
See also
[edit]- 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
[edit]- ^"purescript/purescript".GitHub.3 June 2022.
- ^"PureScript to JavaScript transpiler".GitHub.Retrieved2023-01-22.
- ^"PureScript to C++11 transpiler".GitHub.Retrieved2023-01-22.
- ^purerl - the PureScript Erlang backend,purerl, 2023-09-04,retrieved2023-09-05
- ^"PureScript to Go transpiler".GitHub.Retrieved2023-01-22.
- ^"PureScript".purescript.org.Retrieved2019-03-14.
- ^purescript/documentation,PureScript, 2023-02-19,retrieved2023-02-20
- ^Alternative backends,PureScript, 2023-02-19,retrieved2023-02-20
- ^"Read PureScript by Example | Leanpub".leanpub.Retrieved2019-03-14.
- ^A build tool for PureScript projects,PureScript Contrib, 2019-03-08,retrieved2019-03-14
- ^"Pursuit".pursuit.purescript.org.Retrieved2019-03-14.
- ^🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago,spacchetti, 2019-03-14,retrieved2019-03-14
- ^Documentation for the PureScript language, compiler, and tools.: purescript/documentation,PureScript, 2019-03-14,retrieved2019-03-14
- ^"The Foreign Function Interface".PureScript. 2015-07-15.Retrieved2023-01-22.
- ^"FFI".PureScript. 2019-07-26.Retrieved2023-01-22.
- ^C++ foreign export implementations for the standard library,PureScript, 2019-07-26,retrieved2023-01-22
- ^"Go foreign export implementations for the standard library".PureScript. 2020-12-13.Retrieved2023-01-22.
- ^purs ide: Editor and tooling support for the PureScript programming language,2019-04-21,retrieved2019-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,S2CID218480974