catala icon indicating copy to clipboard operation
catala copied to clipboard

Generate loaders for external modules

Open AltGr opened this issue 1 year ago • 0 comments

Ref. #482

At the moment, we have support for externally implemented modules in a very raw form: an escape hatch allows to provide directly the ml artifact for the module that Catala would normally generate.

The next improvement would provide a nicer interface to external modules, and avoid the need for the user to copy-paste boilerplate and registration code into their module:

  • when tasked with compiling a module tagged external, Catala would generate a "loader" module.
    • This module still takes care of doing the proper registrations and boilerplate (including module hash checks, which at the moment are bypassed for external modules) ;
    • it depends on an implementation module with a provided signature
    • the implementation of the actual functions are just forwarded to the implementation module
  • instead of providing a full Catala artefact with its strict requirements, the user now only supplies the "implementation" module, following the supplied signature

This avoids boilerplate in the user code, improves compilation checks, clarifies requirements upon the user implementation (including if e.g. catala identifiers diverge from ocaml identifiers for some reason), and typing errors can be detected and debugged much more naturally (ie pointing the definition not having the correct type instead of some usage not typing somewhere in generated code).


There is one issue, though: the user code may need to depend, at least in some way, upon some Catala declarations: the functions to be supplied may have to manipulate types defined in Catala. This could be handled nicely be requiring the user to supply a functor with a given type: all type declarations corresponding to struct/enums defined in the current module could be exposed through the functor argument. Extending this, we could allow external modules to depend on other Catala modules... if they need to manipulate the structures or enums they define.

AltGr avatar May 31 '24 13:05 AltGr