ocsigen / eliom

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

Use module aliases for Eliom_content? #437

Open vouillon opened 7 years ago

vouillon commented 7 years ago

I'm wondering whether it would be possible to use module aliases for Eliom_content, in order to avoid loading the interfaces of the three variants F, D and R of the SVG and HTML Tyxml modules when only a few variants are used.

vouillon commented 7 years ago

In fact, we have not three but six copies (!) of the Tyxml signature, with the F.Raw, D.Raw and R.Raw submodules...

vouillon commented 7 years ago

One issue is that we have the following definition:

module Make(Xml : Xml_sigs.T with type ('a, 'b) W.ft = ('a -> 'b))
  : Svg_sigs.Make(Xml).T
    with type +'a elt = Xml.elt
     and type +'a attrib = Xml.attrib

We want to apply this functor several times, exporting the resulting modules from distinct files, remembering that all the 'a elt are the same, while hiding the fact that they are equal to Xml.elt...

I guess one way to achieve that is to have a file containing a definition type +'a elt = Xml.elt and not export the corresponding cmi file.

vouillon commented 7 years ago

Well, if we do not export the cmi file, we no longer have access to the variance information...

As far as I can see, the best we can do is to put the three instantiations F, D and R of the Raw submodules into a same file, with the appropriate interface. But then, we don't save much beside separating Svg from Html: the Raw interfaces are always loaded (as type elt is declared in the same file), the F one is loaded most of the time, and the D one is often loaded as well.

Alternatively, we can just separate Svg and Html, and only export in the Raw submodules the few values that are otherwise overriden.

@Drup, @vasilisp, any comment or idea?

Drup commented 7 years ago

Iirc, the compiler expands the signature in the .cmi only because of the with ... constraints and module type of. If it was a path, only that would be stored. So we don't need to factor out the implementation, just the module type, that should be much easier (since all the interfaces are exactly the same).

This doesn't prevent linking everything, but that's a different problem.

Drup commented 7 years ago

OCaml should probably work a bit harder in this case. Bug report here: https://caml.inria.fr/mantis/view.php?id=7436

vouillon commented 7 years ago

@Drup, that's a good point. Modules F.Raw and D.Raw, as well as modules F and D have the same type. This still leaves some duplication though.

dannywillems commented 7 years ago

Is it not simpler to have Eliom_html instead of Eliom_content.Html?