Marshalling code from jsoo client to native server

Is something like “mobile code” possible between a js client and an ocaml native server, by perhaps marshalling a closure on the client? Reading the docs, it seems probably not. Any ideas?

Essentially, I want the full flexibility of mobile code, rather than going via RPC-like mechanisms.

An alternative that might be also OK: running a bucklescript/node.js server

Sorry for the silly question, but what is a “mobile code”? By the way you talk about it, I don’t think it’s related to mobile apps, and a cursory Google search brought several results which seems to be irrelevant…

I mean code that can travel to a remote site to be executed. Pi calculus popularized this idea.

Like this:

But without the “social ability, learning” etc nonsense

by perhaps marshalling a closure on the client?

How would you stop a user sending your server malicious code to execute?

What are you trying to do that’s hard with RPC?

“How would you stop a user sending your server malicious code to execute?” - In the current setup, this is not something I am bothered about (clients are trusted). But obviously in general this is something one would have to worry about.

“What are you trying to do that’s hard with RPC?” - well, RPC forces you to define upfront what functions you are interested in, and build intensional (bad word) representations. I’d like to avoid that and allow the client “full” (ish) flexibility. For example, let’s say that the global state on the server is some type t. Then I’d like the client to be able to send a function of type t->t to the server and have it executed there. But I don’t want to define intensional representations for all functions of type t -> t.

Perhaps you could define an algebra-like DSL for your type t such that the client can build a computation using this DSL, encode it as an HTTP call and send it to the server; and the server can evaluate and then execute the DSL commands?

I want to avoid defining “computations over t” intensionally (as some kind of datatype). Hence my interest in whether it might be possible to marshal a closure from a client to a server. And to make it easier, both client and server can be running some on some javascript foundation.

OK, the only other thing that comes to mind is Gabriel Gonzalez’ Morte language/implementation which is a sort of bytecode based on typed lambda calculus:

He mentions in that post:

Additionally, Morte might be usable to transmit code in a secure and typed way in distributed environment or to share code between diverse functional language by providing a common intermediate language. However, both of those scenarios require additional work, such as establishing a shared set of foreign primitives and creating Morte encoders/decoders for each target language.

So, it’s probably not something you can use today, but in the future–maybe. And today, the basic idea is probably not that far off from creating your own DSL as I mentioned.