Search code examples
moduleocamlloadingocaml-toplevel

OCaml: Unbound module from parent directory in toplevel


I'm trying to load a module from a parent directory into the top level interpretor.

#load "../Syntax.cmo";;
open Syntax

let foo = bar

Where bar is in Syntax. I have module Syntax in the parent directory. Loading module Syntax does not cause any problems, but the open line throws an error:

Error: Unbound module Syntax

I have also tried removing the open:

#load "../Syntax.cmo";;
let foo = Syntax.bar

But that gives me the same error as Syntax is in the parent directory.

Is there anyway around this?


Solution

  • You shouldn't use relative paths, instead use #directory directive:

    #directory "..";;
    #load "Syntax.cmo";;
    let foo = Syntax.bar;;
    

    Even better, define your library using oasis, or some other high-level tools, and use #require to load your libraries, instead of tackling with low-level directives.