Here at æternity, we’ve envisioned for a long time that running major parts of a blockchain protocol in the context of modern web frameworks would mean a huge leap for the adoption and scalability of distributed ledger technology. What if you could run an ad-hoc blockchain node in your browser, or use state channels to quickly make safe payments using your phone?
As a solid foundation had to be laid for a reliable infrastructure first, that was not conceivable as of yet. Until now.
Besides bringing the components of the æternity blockchain to more platforms and web frameworks, there are two novel use cases for Erlscripten:
2 — The creation of a new paradigm for developing frontend applications.
To demonstrate our point we were capable of taking the compiler of our smart contract language (https://github.com/aeternity/aesophia) and converting it to be runnable in the browser: https://github.com/erlscripten/erlps-aesophia
We tested the transpiled project and it works! Demonstrating our point that we have support for advanced OTP constructs including ETS, Erlang’s in-memory database.
Notably, Lumen has similar goals to our project, after their project is done it will be much faster than Erlscripten and probably more capable — the downside is that Lumen is in WIP phase and it will take a long time for Lumen to be ready whereas Erlscripten is now and here! Ready to be used!
🟩 What is supported
- Majority of Erlang expression
- Arbitrary arity functions
- Pattern matching
- Records (via tuples)
- Tail recursion
- Process dictionaries
- Code server, module loading
- Imports and exports
- Compatibility utilities
- Common errors (function_clause, case_clause, badarity, etc.)
🟧 What is partially supported
⬛️ What is under development
- Leaking variable scopes
- Basic erlang process emulation
- NIFs (will be done through C to WASM compilation)
The original PureScript turned out not to suffice our use case perfectly. For instance, we had some issues regarding handling tail call optimization which started several discussions and contributions on their GitHub:
Some of the problems have been already fixed due to our reports, but some of them haven’t been accepted as they involved some overhead on the performance in the general case. Because of this we have forked the compiler and started adjusting it for our needs ourselves. Our works mainly involve the optimization tweaks and updating the backend to EcmaScript6 (instead of 5). For instance, we have implemented a much more aggressive tail call optimizer, increased strictness of AST traversals and completely rewritten the code generation for pattern match alternatives.
During this work we have spotted some performance bugs and started working on fixing them on our own. One of our patches has already been approved and awaits merging:
While we are perfectly aware that neither Erlang nor PureScript are the most common sight to see, we invite you to take a look: Here are some examples of how Erlscripten transforms existing Erlang code into PureScript. The generated code is obviously larger as we need to take care of the type system (PureScript is typed while Erlang is not) and tackle some syntactic sugars. Furthermore, we need to emulate the default error handling and exceptions that are being solved much differently in Erlang in order to preserve compatibility.
Find the code example here:
Continuation based list reversal via catamorphic transformation:
Find the code example here:
Erlang to PureScript transpiler > https://github.com/erlscripten/erlscripten
Get in touch:
GitHub | Forum | Reddit | Twitter | YouTube| LinkedIn