Code Monkey home page Code Monkey logo

ocaml's Introduction

This is my personal hack of ocaml to readable javascript backend in the module level.

This code is a mirror of my private repo(not production ready yet), it's generated code from another git repo of my compiler.

You can read generated js code for each ml file, for example stdlib/array.js

You can play the online in-browser compiler. If you are interested in this project, please contact [email protected]

See ./stdlib/*.js to have a look at generated js code for ocaml standard library, it should be fairly easy to integrate it with nodejs or using webpack to bundle it into browser

var $$Array = require('./array.js');
var List = require ('./list.js');
List.iter(function(x){console.log('hi, nodejs '+x)},
    $$Array.to_list ($$Array.init(5,function(x){return x})))

You get the output:

hi, nodejs 0
hi, nodejs 1
hi, nodejs 2
hi, nodejs 3
hi, nodejs 4

Design goal

  1. High quality generate code in dev mode, integrate with existing javascript echo system. straight-forward FFI, generate tds file to target typescript for better tooling

  2. Highly performant: thanks to a sound type system in ocaml so that we can play more optimizations.

  3. Separate compilation, extremely fast compilation.

  4. Global dead code elimination in production mode

  5. Very thin run-time or zero run-time, support nodejs, webbrowser.

6 Highly compatible with ocaml semantics modulo c-bindings and Obj module

Status

This is my hobby project at night, currently, things which need be polished:

  1. Make sure runtime support is correct, currently we borrow the runtime library stdlib/camlPrimitive.js from js_of_ocaml, but we can have better runtime encoding in ocamlscript, so I would like to write my own runtime library and make it thin.

  2. Direct tail call support.

  3. Curry function wrap and un-wrap

Future work

Make a javascript front-end to OCaml using javascript-like syntax (write a javascript parser for ocaml like fan), which makes our language really javascript like, the generated code would be even more readable.

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.