ocsigen / eliom

Multi-tier framework for programming web and mobile applications in OCaml.
http://eliom.org
Other
301 stars 53 forks source link

Interoperability with Reason (ReasonML) #410

Open dannywillems opened 7 years ago

dannywillems commented 7 years ago

Some months ago, Facebook released Reason which aims to easily switch to OCaml by implementing a syntax extension close to other popular languages and it gains rapidly in popularity. To compare to OCaml, since the realease, they are more stars on the Reason GitHub (more than 1800) than OCaml (around 1000) and Reason has a very huge community.

And the entire Ocsigen project (Eliom, TyXML, JSOO, Ocsigen-start, ...) must have a place in this community. The Ocsigen framework has a lot of concepts which are implemented in any other languages.

I think a collaboration between the Ocsigen and the Reason teams will be a great opportunity and a chance for both, and for both communities.

@balat Yesterday, you said you wanted more ocsigen-start users: it's a real opportunity, even for Be Sport (because more collaborators).

I hope this issue can be a place to discuss about it and begin a collaboration to make Ocsigen and Reason better.

Drup commented 7 years ago

cc @chenglou @jordwalke :p

Would be interesting to have a rebuild-ocsigen thingy. The build aspect has always been a mess in eliom, that could help quite a bit.

The other point is the various syntax extensions we have (in particular the eliom one) but afaik, ppx works just fine in reason, so that should not be an issue.

dannywillems commented 7 years ago

Maybe also cc @sanderspies and @yunxing (based on contributions)?

jordwalke commented 7 years ago

Cool idea. All ppx extensions should work in Reason, and if you find any that don't, it's a bug and should be fixed.

Is there a place for Reason's new (but experimental) JSX implementation? It allows concrete syntax of XML - which merely translates into named argument function calls.

<thisRightHere argOne="hi"> <child /> </thisRightHere >

Becomes:

thisRightHere argOne::"hi" [child]

Or OCaml's

thisRightHere ~argOne:"hi" [child]
Drup commented 7 years ago

As you know, we already have an html api (https://github.com/ocsigen/tyxml/) and an associated PPX. The API looks like this:

element ~a:[attr] [child]

There are various typing reasons for having this a argument for all the attributes, and changing it would break compat with a lot of things, so that's not really reasonable. We could have an overlay to expose an API such that JSX works. That would be a lot of work though.

jordwalke commented 7 years ago

We can also change JSX as well, if needed -I'm just curious if one approach is fundamentally better than the other. If tyxml is doing something better, we could change JSX to match. But as it stands, I really enjoy named arguments for things you'd normally use "XML" syntax to represent, because it prevents passing an attribute twice. Aren't OCaml's labeled arguments also optimized such that (unless using the partial application), it calls the function immediately without going through all the intermediate partial applications/allocations?

I think in the case of HTML, it might end up being more efficient to do it via the Tyxml way because 95% of all the arguments are never specified, so the functions would end up being invoked with a bunch of None None None None ... arguments for all the attributes not specified. I think the JSX approach works better for custom components (like <MyWidget user=joe />) which typically accept far fewer "attributes".

I'm just trying to get your thoughts on which is better and in which cases.

Drup commented 7 years ago

Tyxml can be seen as a (generic) typed overlay over untyped arbitrary XML implementations. The goals are 1) type safety 2) genericity 3) low overhead over the XML implementation. Keeping that in mind:

So, what I'm saying is that it would be a lot more effort to make tyxml with optional arguments, and tyxml is complicated enough. :p The flip side of all that, of course, is that the API is less convenient/more verbose, as you said.

Aren't OCaml's labeled arguments also optimized such that (unless using the partial application), it calls the function immediately without going through all the intermediate partial applications/allocations?

If you mean optional arguments, no they are not, it uses an option type underneath. If you mean regular labels, it's exactly equivalent to function application.

Drup commented 7 years ago

Side note: I didn't made that choice, it was already like that when I started working on ocsigen. I just think that, given the constraints, it's a decent choice :)

jordwalke commented 7 years ago

If you mean optional arguments, no they are not, it uses an option type underneath.

No I just meant labeled arguments in general. I understand that the optional ones become None/Some x.