2 ms·
OCaml doesn't have a C-style preprocessor, but I sometimes wish it did have one. One case is where a function has changed its type signature, eg. adding a para
by rwmj 10y ago
OCaml doesn't have a C-style preprocessor, but I sometimes wish it did have one. One case is where a function has changed its type signature, eg. adding a parameter, but you still want to be able to write code that can compile with the old and new versions of the library. It would be quickest to write:
#if HAVE_OLD_LIB
f 1 2;
#else
f 1 2 3;
#endif
The actual solution in pure OCaml is a huge pain. Usually you have to add another module which is conditionally compiled.
Luckily in OCaml you can write ‘ocamlopt -pp cpp’ to use the C preprocessor on selected files.