91 points · by DanielRibeiro · 14y ago · 32 comments
(Obviously C can't be that language for the web (NaCl possibly excluded), but when I say C, I mean in the general profile: extremely simple and maps very closely to what the hardware is actually doing)
1. Bytecode formats are never completely language independent - there's always a feature or change that would make language X better
2. Browser vendors will never be able to agree on a bytecode format
So, to solve those problems, I've been thinking the following approach might work:
1. Write a JavaScript interpeter for a fairly language-independent bytecode
2. Write some small languages, targeting that bytecode (something for everyone: Haskell-like, C-like, Lisp-like, Forth-like, etc)
3. Hope people start writing more languages to target the bytecode
4. Hope that it's hard for browser vendors to ignore implementing the bytecode natively - for performance reasons
This way we avoid committees and just get it done. Let me know if you think this is a good or bad idea. I'm very willing to work on it.
Moreover, it’d be trivial for browser authors to implement, so for a very low investment there could be a huge return. You can write a basic runtime for a full-featured concatenative language in a few hundred lines of C, and a compiler for it in a few dozen lines of Haskell.
My bet would be a minimal standard library, based on empirically most useful functionality. I very much doubt you'd need more than a thousand lines to implement that (not counting a possibly crap-load of optimizations).
I would love to see a formal specification for the language mapping Roy's syntax to a subset of JS. It would also be nice if the primary implementation were written in OCaml or Haskell. Both of these languages now have very reliable ML->JS compilers and support algebraic data types allowing you to precisely model your object language.
But I think CoffeeScript has shown that in-browser compilation and execution is very useful. For example, if I wrote Roy in Haskell, I wouldn't have been able to easily write this demo site:
It means you can play with Roy just by hitting a URL - low barrier to entry.
Another benefit is that you can include the Roy compiler in a page and use that to compile your Roy code - no pre-compilation necessary.
I will actively contribute to your language implementation and use of these tools should you adopt them. With a proper type system, you can change the world. Without a proper type system, we will all suffer and kill ourselves by a thousand cuts.
If you have further doubts about the viability of this approach, see http://ashimagroup.net/demo/game/ooman/tutorial/ for a rigid body motion model in an OCaml WebGL game compiled to JS.
You don't have to sell me on type systems - they're exactly why I'm working on Roy.
> If you have further doubts about the viability of this approach, see http://ashimagroup.net/demo/game/ooman/tutorial/ for a rigid body motion model in an OCaml WebGL game compiled to JS.
I know that compiling languages with completely different semantics to JavaScript is possible (I even maintain http://altjs.org/). But they present two problems:
1. They output to ugly JavaScript that is hard to interop with and/or people can't reason about
2. They need a huge runtime
The resultant JavaScript you linked to was ~300K.
Roy takes a different approach and tries to stay semantically close to JavaScript when possible. This is to combat both of the above problems. I'd love to see a Roy example of that demo - I imagine the JavaScript would be a lot more readable and smaller.
It doesn't matter what the target language is if you want to do static typing or type inference. For example, Haskell compiles down to assembly, but still has an extremely robust type system with inference and all.
>> severely restrict the target platforms and future growth
Are you serious? JavaScript is supported on every platform and is experiencing crazy growth.
I am very serious. JavaScript is terrible for analysis and a huge waste on the server-side or mobile. Choosing JavaScript as the metalanguage for an implementation of an HM type system is strange. Why have an HM type system itself written in a type-unsafe way? Why artificially limit the analyzability of the language implementation which is pure and simply string(Roy) -> string(JS)? Roy looks like it has great potential and one of the reasons for that potential is its nascent type system. I want to take my pure Roy function library to ObjC, OCaml, C--, etc.
not sure how much has changed since then.
CoffeeScript is certainly a pleasure to work with but it lacks a type system and static type checking.
Though I think it takes quite some experience programming in Ocaml/ML/Haskell to fully appreciate its power.