Quire

PureScript

From Quire, the open reference··1 min read
PureScript
PureScript
编程范型函数式
設計者Phil Freeman
发行时间2013年
当前版本0.15.16(2026年3月15日;穩定版本)[1]
類型系統类型推论, 静态, 强类型
許可證三条款BSD许可证[2]
文件扩展名.purs
網站www.purescript.org
受影响于
Haskell, JavaScript

PureScript是一种强类型、纯函数式、最终编译为JavaScript的编程语言。PureScript可以开发网络应用程序、服务端应用程序,也可以借助Electron开发桌面应用程序。其语法大多与Haskell相当[3]。此外,它还引入了行多态性和可扩展记录。[4]不过,与Haskell相反的是,PureScript坚持严格求值策略。

历史#edit

PureScript最初由费尔·弗里曼在2013年设计[5]。他曾屡次尝试在保留語義的情況下,将Haskell编译成JavaScript(如使用Fay、Haste或GHCJS[6]),但结果并不满意,於是他开始着手在PureScript上工作。[7]

从此以后它由社区接手并在GitHub继续开发[8]。社区开发的额外核心工具包括专门的构建工具Pulp[9]、文档目录Pursuit[10]和包管理器Spago[11]。

特征#edit

PureScript特征主要为严格求值、持久性数据结构和类型推论。PureScript的类型系统同类似的函数式语言如Haskell共享了很特征:代数数据类型及模式匹配、高种类类型、类型类及函数依赖和高秩多态。PureScript的类型系统增加了对行多态和可扩展记录的支持[12]。但是,PureScript缺乏对Haskell的某些更高级特征如GADT和类型家族的支持。

PureScript编译器尝试产生尽可能可读的JavaScript代码。通过一个简单的FFI接口,它还允许重用现存的JavaScript代码[12]。

PureScript支持增量编译,而且编译器发行包括了支持为迭代开发建造源代码编辑器插件[13]。存在编辑器插件针对很多流行的编辑器,包括Vim、Emacs、Sublime Text、Atom和Visual Studio Code。

PureScript通过它的“类型孔洞”特征支持“类型驱动开发”[14],在其中可以构造具有缺失子表达式的程序。编译器随后将尝试推论出缺失子表达式的类型,并将这些类型报告给用户。这个特征已经启发了GHC的类似工作[15]。

示例#edit

一个最精简的Hello world程序如下:

module Main where

import Effect.Console (log)

main = log "Hello World!"

在这里,程序的类型是由PureScript编译器推论出并检查。相同程序的更冗长版本可以包括显式的类型标注:

module Main where

import Prelude

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

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

参见#edit

引用#edit

  1. ^ Release 0.15.16. 2026年3月15日 [2026年4月7日].
  2. ^ purescript/purescript. GitHub. [2021-02-14]. (原始内容存档于2021-04-25).
  3. ^ PureScript for the Haskeller - Where to get started in PureScript for the Haskell programmer. [2021-02-28]. (原始内容存档于2020-11-08).
  4. ^ PureScript. www.purescript.org. [2019-03-14]. (原始内容存档于2021-02-05).
  5. ^ PureScript - Strongly Typed Programming Language Compiling to JavaScript - Interview with Phil Freeman. [2021-02-28]. (原始内容存档于2021-01-18).
  6. ^ The JavaScript Problem. [2021-02-28]. (原始内容存档于2020-12-09).
  7. ^ Read PureScript by Example | Leanpub. leanpub.com. [2019-03-14]. (原始内容存档于2020-11-29).
  8. ^ awesome-purescript. [2021-02-28]. (原始内容存档于2021-11-21).
  9. ^ A build tool for PureScript projects, PureScript Contrib, 2019-03-08 [2019-03-14], (原始内容存档于2020-12-05)
  10. ^ Pursuit. pursuit.purescript.org. [2019-03-14]. (原始内容存档于2021-03-01).
  11. ^ 🍝 PureScript package manager and build tool powered by Dhall and package-sets: spacchetti/spago, spacchetti, 2019-03-14 [2019-03-14]
  12. ^ a b Documentation for the PureScript language, compiler, and tools.: purescript/documentation, PureScript, 2019-03-14 [2019-03-14], (原始内容存档于2021-04-25)
  13. ^ purs ide: Editor and tooling support for the PureScript programming language, 2019-04-21 [2019-04-21], (原始内容存档于2025-12-06)
  14. ^ Implementing type directed search for PureScript, 2016-10-27
  15. ^ Matthías Páll Gissurarson, Suggesting Valid Hole Fits for Typed-Holes (Experience Report), 2018-09-27

外部链接#edit

This article is mirrored from “PureScript” on 中文 Wikipedia, revision 94366253, written by Wikipedia's contributors and licensed CC BY-SA 4.0. Editing it here creates a Quire copy with its own history.

Synced with Wikipedia revision 94366253 · just now