Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smorimoto/coq-to-ocaml-to-js
Proof of concept to generate safe and fast JavaScript
https://github.com/smorimoto/coq-to-ocaml-to-js
bucklescript coq javascript ocaml proof
Last synced: 2 months ago
JSON representation
Proof of concept to generate safe and fast JavaScript
- Host: GitHub
- URL: https://github.com/smorimoto/coq-to-ocaml-to-js
- Owner: smorimoto
- License: apache-2.0
- Created: 2019-10-24T03:24:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-08-07T15:30:42.000Z (over 2 years ago)
- Last Synced: 2024-10-04T12:55:23.226Z (3 months ago)
- Topics: bucklescript, coq, javascript, ocaml, proof
- Language: JavaScript
- Homepage:
- Size: 402 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# coq-to-ocaml-to-js
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/imbsky/coq-to-ocaml-to-js/Main%20workflow?style=flat-square)](https://github.com/imbsky/coq-to-ocaml-to-js/actions)
[![GitHub package.json version](https://img.shields.io/github/package-json/v/imbsky/coq-to-ocaml-to-js?style=flat-square)](https://github.com/imbsky/coq-to-ocaml-to-js/blob/master/package.json)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![GitHub](https://img.shields.io/github/license/imbsky/coq-to-ocaml-to-js?color=brightgreen&style=flat-square)](https://github.com/imbsky/coq-to-ocaml-to-js/blob/master/LICENSE)## Overview
This repository is nothing more than a proof of concept using Coq's Extraction,
BuckleScript, Rollup, Terser, and Closure Compiler to generate safe and fast
JavaScript.### What is Coq
> Coq is a proof assistant. It means that it is designed to develop mathematical
> proofs, and especially to write formal specifications, programs and proofs
> that programs comply to their specifications. An interesting additional
> feature of Coq is that it can automatically extract executable programs from
> specifications, as either Objective Caml or Haskell source code. -
> [A short introduction to Coq](https://coq.inria.fr)### What is BuckleScript
> BuckleScript isn't a new language. It simply takes OCaml, a fast, pragmatic
> and typed language, and makes it compile to clean, readable and performant
> JavaScript code. -
> [What is BuckleScript?](https://bucklescript.github.io/docs/en/what-why)### Workflow and directory structure
```
Coq Code
|
| (Use Coq Compiler)
v
OCaml Code
|
| (Use BuckleScript)
v
Optimized JavaScript Code
|
| (Use Rollup, Terser, Closure Compiler)
v
More Optimized JavaScript Code
```### Source code
```coq
Fixpoint f n :=
match n with
| O => nat
| S n => nat -> (f n)
end.Definition sigma: forall n, f n.
intro n; induction n; simpl.
exact O.
intro m.
destruct n; simpl in *.
exact m.
intro o.
apply IHn.
exact (m+o).
Defined.
```### Generated codes
`sigma.ml`
```ocaml
type __ = Obj.t
type nat = O | S of nat(** val add : nat -> nat -> nat **)
let rec add n m = match n with O -> m | S p -> S (add p m)
type f = __
(** val sigma : nat -> f **)
let rec sigma = function
| O -> Obj.magic O
| S n0 ->
Obj.magic (fun m ->
match n0 with
| O -> m
| S _ -> fun o -> Obj.magic sigma n0 (add (Obj.magic m) o))
````sigma.mli`
```ocaml
type __ = Obj.t
type nat = O | S of natval add : nat -> nat -> nat
type f = __
val sigma : nat -> f
````sigma.js`
```javascript
import * as Curry from "rescript/lib/es6/curry.js";function add(n, m) {
if (n) {
return /* S */ {
_0: add(n._0, m),
};
} else {
return m;
}
}function sigma(n0) {
if (!n0) {
return /* O */ 0;
}
var n0$1 = n0._0;
return function (m) {
if (n0$1) {
return function (o) {
return Curry._1(sigma(n0$1), add(m, o));
};
} else {
return m;
}
};
}export { add, sigma };
```## Build
See the file [BUILD.md](BUILD.md) for build instructions.
## License
Licensed under the
[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).