yongqian10 / CP-next

The Next Generation of Compositional Programming

Home Page:https://plground.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CP - The Next Generation

CP is a compositional programming language, founded on a core calculus named Fi+. The next-gen CP is shipped with more features and implemented in PureScript (a Haskell-like language that compiles to JavaScript).

Language Features

  • A typed lambda calculus with six base types (Int Double String Bool Top Bot), built-in arrays ([1; 2; 3] : [Int]), and some built-in operations over them;
  • A merge operator 1, disjoint intersection types 2 and disjoint polymorphism 3;
  • Nested composition and distributive subtyping 4;
  • Compositional Programming 5 with first-class traits 6;
  • Type-directed operational semantics for Fi+ 7 with {substitution,closure,HOAS}-based {big,small}-step variants;
  • An embedded DSL for document authoring called ExT 8.

Online Demo

PLGround provides an online CP interpreter and a wiki-like document repository. Documents are written in ExT and rendered in your web browser.

Since the frontend code uses the Fetch API, PLGround is expected to work on Chrome 42+, Firefox 39+, Edge 14+, Safari 10.1+, or other modern browsers.

CLI Setup

If you want to run CP programs locally using a CLI, you can follow the procedure below:

  • First of all, you need to install Node.js.
  • Then execute npm install to get all of the dev dependencies.
  • After installation, you can choose either of the following npm scripts:
    • npm start to run a REPL;
    • npm test to run a test suite checking examples/*.cp.

If you want to start a PLGround server locally, take the first two steps above and then:

  • Install Ruby.
  • Execute bundle install to get Ruby on Rails and other gems.
  • Execute npm run build if you have modified PureScript code, grammar files, or app.js (i.e. every file that plground/app/assets/javascripts/bundle.js depends on).
  • Execute npm run server to start a web server.

REPL Example

$ npm start
......
Next-Gen CP REPL, version x.x.x

> :load examples/bench.cp
7773
<BigStep mode: 1.024s>

> :mode StepTrace

> 1+2*3
(1 + (2 * 3))
......
(1 + 6)
↓ Step-BinaryV
7
<StepTrace mode: 0.021s>

Grammar Maintenance

There are currently four different copies of the CP grammar. If you want to modify the grammar, please remember to change them all:

  1. PureScript parser based on parser combinators, used in REPL (see the code here).
  2. ANTLR-generated LL(*) parser, used in PLGround (see this directory).
  3. Lezer-generated incremental parser for the CodeMirror 6 code editor (see the grammar file).
  4. TextMate grammar specification for VS Code, mainly keyword highlighting (see the JSON file).

VS Code Extension

CP language support can be found on VS Code Marketplace.

If you want to build it from scratch, please execute npm run vscode. Then a .vsix file will be generated in vscode/.

Next-Gen CP versus Original CP

The original CP (hereinafter CP1) is introduced and formalized in our TOPLAS paper Compositional Programming. Its reference implementation is included in the artifact. The next-gen CP (hereinafter CP2) polishes the syntax of CP1 and extends it with new features, but their semantics are essentially the same. CP2 has a brand-new implementation that supersedes the original one.

Concerning implementation languages, CP1 is written in Haskell, while CP2 is written in PureScript. Thus, CP2 can easily run in a web browser without losing the ability to run traditionally in a terminal. Concerning the semantics of the core calculus Fi+, it is further elaborated to F-co in CP1 but has direct operational semantics in CP2. Furthermore, new features recently added and some syntactic differences can be found at CHANGELOG.md.

Footnotes

  1. Jana Dunfield. Elaborating Intersection and Union Types. In JFP 2014.

  2. Bruno C. d. S. Oliveira, Zhiyuan Shi, and João Alpuim. Disjoint Intersection Types. In ICFP 2016.

  3. João Alpuim, Bruno C. d. S. Oliveira, and Zhiyuan Shi. Disjoint Polymorphism. In ESOP 2017.

  4. Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. The Essence of Nested Composition. In ECOOP 2018.

  5. Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. Compositional Programming. In TOPLAS 2021.

  6. Xuan Bi and Bruno C. d. S. Oliveira. Typed First-Class Traits. In ECOOP 2018.

  7. Andong Fan, Xuejing Huang, Han Xu, Yaozhu Sun, and Bruno C. d. S. Oliveira. Direct Foundations for Compositional Programming. In ECOOP 2022.

  8. Yaozhu Sun, Utkarsh Dhandhania, and Bruno C. d. S. Oliveira. Compositional Embeddings of Domain-Specific Languages. Unpublished.

About

The Next Generation of Compositional Programming

https://plground.org

License:Other


Languages

Language:PureScript 53.2%Language:Ruby 16.7%Language:JavaScript 13.0%Language:TeX 6.8%Language:HTML 4.9%Language:ANTLR 3.3%Language:Dhall 1.6%Language:CSS 0.3%Language:Makefile 0.1%