ArticleslgStudy

computer science

PureScript

PureScript is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand PureScript rather than just read about it. In short: PureScript is a strongly typed, purely functional programming language that transpiles to JavaScript and, with alternate backends, to C++11, Erlang, and Go. 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.

PureScript — main illustration
PureScript — illustration

Key takeaways

  • PureScript belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect PureScript to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of PureScript from memory before moving on to harder problems.

Reference excerpt

PureScript is a strongly typed, purely functional programming language that transpiles to JavaScript and, with alternate backends, to C++11, Erlang, and Go. 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. Also, it introduces row polymorphism and extensible records. 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. It is free and open-source software released under a BSD 3-clause license.

History PureScript was initially designed by Phil Freeman in 2013. He began work on it because he was unsatisfied by other attempts to transpile Haskell to JavaScript (e.g., using Fay, Haste, or GHCJS). Since then it has been adopted by the community and is developed on GitHub. Further community-developed core tools include the dedicated build tool Pulp, the documentation directory Pursuit, and the package manager Spago.

Features PureScript features strict evaluation, persistent data structures, and type inference. Its data type system shares many features with those of similar functional languages like Haskell: algebraic data types and pattern matching, higher kinded types, type classes, functional dependencies, and higher-rank polymorphism. Its type system adds support for row polymorphism and extensible records, but does not support some of the more advanced features of Haskell such as the generalized algebraic data type (GADT) and the type family. The PureScript transpilers attempt to produce readable code, where possible. Through a simple foreign function interface (FFI), it also allows code reuse of extant source code in JavaScript, C++11, and Go, usually as an intermediate representation. PureScript supports incremental compilation, and the transpiler to JavaScript distribution supports building source-code editor plug-ins for iterative development. Editor plug-ins 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 inspired similar work in the Glasgow Haskell Compiler (GHC).

Examples Here is a minimal "Hello, World!" program in PureScript:

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:

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

External links Official website PureScript Playground

Illustrations

PureScript illustration
PureScript illustration

Worked examples

Example 1 — a first encounter with PureScript

Start with the simplest possible case. Write down what PureScript claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to PureScript before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about PureScript ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of PureScript

In research
PureScript appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses PureScript in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
PureScript is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2013 software, Functional languages, Pattern matching programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for PureScript outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “PureScript” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study PureScript in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what PureScript means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain PureScript out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is PureScript in simple terms?

PureScript is a strongly typed, purely functional programming language that transpiles to JavaScript and, with alternate backends, to C++11, Erlang, and Go. 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…

Why does PureScript matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study PureScript?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on PureScript.

Tags

  • 2013 software
  • Functional languages
  • Pattern matching programming languages
  • Programming languages created in 2013
  • Software using the BSD license
  • Statically typed programming languages

Keep exploring