0

I want to do the command #use "a.ml" conditionally i.e., in 'if statement' as shown below...

let funs = function (true) -> #use "1.ml"
| (false)-> #use "2.ml";;
is there any way of doing it?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281

1 Answers1

6

The #use directive is part of the interpretive environment (REPL) of the OCaml toplevel. It's not a construct of the OCaml language itself. So your example code makes no sense as an OCaml program.

However, it's pretty clear what you want to do: you want to choose between two implementations of a set of functions (i.e., two modules) at runtime.

This is what first-class modules are for. See this excellent SO answer.

Community
  • 1
  • 1
Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108