I am writing a program which parses scripts written in some made-up language and does some computations using that script. This language has a particular construct which is used to call external OCaml functions of the type 'a -> bool
. So, in the middle of the language we may have
blah blah function (foo 45) blah blah
and I'd like the parser to use a constructor such as
OCamlFunction of ('a -> bool) * 'a
to parse that bit as the value
OCamlFunction (foo,45)
where 'foo' is a function that the user will have to provide in a separate .ml file and which the parser doesn't know beforehand; only the name of the OCaml file where "foo" is defined is passed to the parser at runtime. So, I need to define a function of type string->('a->bool)
which takes the name of some function and returns that function.
My questions are:
(1) I'm assuming that the dynamic loading of code should use DynLink.loadfile. Is this the way to go?
(2) How do I get access to the function "foo" from the knowledge of its identifier? (Will this lead me to camlp5?)