Coder Social home page Coder Social logo

yzyzsun / cp-next Goto Github PK

View Code? Open in Web Editor NEW
20.0 6.0 4.0 27.9 MB

The Next Generation of Compositional Programming

Home Page: https://plground.org

License: Other

HTML 1.77% JavaScript 4.74% PureScript 22.92% Ruby 5.93% CSS 0.11% Makefile 0.25% TeX 11.91% ANTLR 1.20% Dhall 0.57% Coq 50.59%

cp-next's Introduction

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 five base types (Int Double String Bool ()), built-in arrays ([1; 2; 3] : [Int]), and some built-in operations over them;
  • The merge operator1, disjoint intersection types2 and disjoint polymorphism3;
  • Generalized record operations with type difference4;
  • Iso-recursive types with nominal unfoldings5;
  • Nested composition and distributive subtyping6;
  • Compositional programming7 with first-class traits8;
  • Type-directed operational semantics for Fi+9 with {HOAS,substitution,closure}-based {big,small}-step variants;
  • A compositionally embedded DSL for document authoring called ExT10.

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 run compiler "*.cp" to compile CP files to JavaScript;
    • 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, dev version (default mode: HOAS)

> :mode StepTrace
> 1+2*3

(1 + (2 * 3))
......
(1 + 6)
↓ Step-BinaryV
7

> :timing
> :mode HOAS
> :load examples/bench.cp

125000
Time: 1.024s

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. Han Xu, Xuejing Huang, and Bruno C. d. S. Oliveira. Making a Type Difference. In POPL 2023.

  5. Yaoda Zhou, Jinxu Zhao and Bruno C. d. S. Oliveira. Revisiting Iso-Recursive Subtyping. In TOPLAS 2022.

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

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

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

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

  10. Yaozhu Sun, Utkarsh Dhandhania, and Bruno C. d. S. Oliveira. Compositional Embeddings of Domain-Specific Languages. In OOPSLA 2022.

cp-next's People

Contributors

dependabot[bot] avatar jimmyzjx avatar paulzfm avatar xsnow avatar yoodee avatar yzyzsun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.