Jump to content

PureScript: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Minimal hello world example
Remove empty sections, rearrange
Line 21: Line 21:
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"<ref>{{Citation|title=A build tool for PureScript projects|date=2019-03-08|url=https://github.com/purescript-contrib/pulp|publisher=PureScript Contrib|access-date=2019-03-14}}</ref>, the documentation directory "Pursuit"<ref>{{Cite web|url=https://pursuit.purescript.org/|title=Pursuit|website=pursuit.purescript.org|access-date=2019-03-14}}</ref>, and the package manager "Spago"<ref>{{Citation|title=🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago|date=2019-03-14|url=https://github.com/spacchetti/spago|publisher=spacchetti|access-date=2019-03-14}}</ref>
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"<ref>{{Citation|title=A build tool for PureScript projects|date=2019-03-08|url=https://github.com/purescript-contrib/pulp|publisher=PureScript Contrib|access-date=2019-03-14}}</ref>, the documentation directory "Pursuit"<ref>{{Cite web|url=https://pursuit.purescript.org/|title=Pursuit|website=pursuit.purescript.org|access-date=2019-03-14}}</ref>, and the package manager "Spago"<ref>{{Citation|title=🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago|date=2019-03-14|url=https://github.com/spacchetti/spago|publisher=spacchetti|access-date=2019-03-14}}</ref>



== Type System ==
== Features ==
PureScript features [[Eager_evaluation|strict evaluation]], [[persistent data structures]] and [[type inference]]. The PureScript type system shares many features with those of similar functional languages like [[Haskell (programming language)|Haskell]]: [[Algebraic data type|algebraic data types]] and [[Pattern matching|pattern matching]], [[Higher-kinded type|higher kinded types]], [[Type class|type classes]] and [[Type_class#Functional_dependencies|functional dependencies]], and [[Higher-rank polymorphism|higher-rank polymorphism]]. Perhaps most notably, PureScript's type system adds support for [[Row polymorphism|row polymorphism]] and extensible records.<ref>{{Citation|title=Documentation for the PureScript language, compiler, and tools.: purescript/documentation|date=2019-03-14|url=https://github.com/purescript/documentation|publisher=PureScript|access-date=2019-03-14}}</ref> However, PureScript lacks support for some of the more advanced features of Haskell like [[Generalized_algebraic_data_type|GADTs]] and [[Type_family|type families]].

The PureScript compiler attempts to produce readable JavaScript code, where possible. Through a simple FFI interface it also allows the reuse of existing JavaScript code.<ref>{{Citation|title=Documentation for the PureScript language, compiler, and tools.: purescript/documentation|date=2019-03-14|url=https://github.com/purescript/documentation|publisher=PureScript|access-date=2019-03-14}}</ref>

PureScript supports [[incremental compilation]], and the compiler distribution includes support for building [[source code editor]] plugins for iterative development<ref>{{Citation|title=purs ide: Editor and tooling support for the PureScript programming language|date=2019-04-21|url=https://github.com/purescript/purescript/tree/dfbd19da85c92d82ed4c3184f950f74da5332e3f/psc-ide|access-date=2019-04-21}}</ref>. Editor plugins exist for many popular text editors, including [[Vim_(text_editor)|Vim]], [[Emacs]], [[Sublime Text]], [[Atom_(text_editor)|Atom]] and [[Visual Studio Code]].


== Code Examples ==
== Code Examples ==
Line 44: Line 50:
</syntaxhighlight>
</syntaxhighlight>


== Features ==
PureScript features [[Eager_evaluation|strict evaluation]], [[persistent data structures]] and [[type inference]]. The PureScript type system shares many features with those of similar functional languages like [[Haskell (programming language)|Haskell]]: [[Algebraic data type|algebraic data types]] and [[Pattern matching|pattern matching]], [[Higher-kinded type|higher kinded types]], [[Type class|type classes]] and [[Type_class#Functional_dependencies|functional dependencies]], and [[Higher-rank polymorphism|higher-rank polymorphism]]. Perhaps most notably, PureScript's type system adds support for [[Row polymorphism|row polymorphism]] and extensible records.<ref>{{Citation|title=Documentation for the PureScript language, compiler, and tools.: purescript/documentation|date=2019-03-14|url=https://github.com/purescript/documentation|publisher=PureScript|access-date=2019-03-14}}</ref> However, PureScript lacks support for some of the more advanced features of Haskell like [[Generalized_algebraic_data_type|GADTs]] and [[Type_family|type families]].

The PureScript compiler attempts to produce readable JavaScript code, where possible. Through a simple FFI interface it also allows the reuse of existing JavaScript code.<ref>{{Citation|title=Documentation for the PureScript language, compiler, and tools.: purescript/documentation|date=2019-03-14|url=https://github.com/purescript/documentation|publisher=PureScript|access-date=2019-03-14}}</ref>

PureScript supports [[incremental compilation]], and the compiler distribution includes support for building [[source code editor]] plugins for iterative development<ref>{{Citation|title=purs ide: Editor and tooling support for the PureScript programming language|date=2019-04-21|url=https://github.com/purescript/purescript/tree/dfbd19da85c92d82ed4c3184f950f74da5332e3f/psc-ide|access-date=2019-04-21}}</ref>. Editor plugins exist for many popular text editors, including [[Vim_(text_editor)|Vim]], [[Emacs]], [[Sublime Text]], [[Atom_(text_editor)|Atom]] and [[Visual Studio Code]].

== Ecosystem ==
== Applications ==
== Future Directions ==
== See also ==
== See also ==
{{Portal|Free and open-source software}}
{{Portal|Free and open-source software}}

Revision as of 17:38, 21 April 2019

PureScript
ParadigmFunctional
Designed byPhil Freeman
First appeared2013
Stable release
0.12.5 / April 14, 2019; 5 years ago (2019-04-14)
Typing disciplineStatic, Strong, Inferred
LicensePermissive (Modified BSD License)[1]
Filename extensions.purs
Websitewww.purescript.org
Influenced by
Elm, F#, Haskell, Koka, OCaml, Roy, Standard ML

PureScript is a strongly-typed, purely-functional programming language that compiles to JavaScript. It can be used to develop web applications, server side apps, and also desktop applications with use of Electron. Its syntax is mostly comparable to that of Haskell. In addition, it introduces row polymorphism and extensible records.[2] Also, contrary to Haskell, PureScript adheres to a strict evaluation strategy.

History

PureScript was initially designed by Phil Freeman in 2013. He started to work on PureScript as various attempts to compile Haskell to JavaScript while preserving its semantics (e.g. using Fay, Haste, or GHCJS) didn't work to his satisfaction.[3]

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


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. Perhaps most notably, PureScript's type system adds support for row polymorphism and extensible records.[7] However, PureScript lacks support for some of the more advanced features of Haskell like GADTs and type families.

The PureScript compiler attempts to produce readable JavaScript code, where possible. Through a simple FFI interface it also allows the reuse of existing JavaScript code.[8]

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

Code 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 compiler. 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: A domain-specific programming language for declaratively creating web browser-based graphical user interfaces
  • TypeScript: A strongly-typed programming language that transpiles to JavaScript

References

  1. ^ "purescript/purescript". GitHub.
  2. ^ "PureScript". www.purescript.org. Retrieved 2019-03-14.
  3. ^ "Read PureScript by Example | Leanpub". leanpub.com. Retrieved 2019-03-14.
  4. ^ A build tool for PureScript projects, PureScript Contrib, 2019-03-08, retrieved 2019-03-14
  5. ^ "Pursuit". pursuit.purescript.org. Retrieved 2019-03-14.
  6. ^ 🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago, spacchetti, 2019-03-14, retrieved 2019-03-14
  7. ^ Documentation for the PureScript language, compiler, and tools.: purescript/documentation, PureScript, 2019-03-14, retrieved 2019-03-14
  8. ^ Documentation for the PureScript language, compiler, and tools.: purescript/documentation, PureScript, 2019-03-14, retrieved 2019-03-14
  9. ^ purs ide: Editor and tooling support for the PureScript programming language, 2019-04-21, retrieved 2019-04-21