Duneのモジュール
dune init project foo && cd fooする.
libにfoo.mlとbar.mlを作成する
code:tree
.
├── bin
│ ├── dune
│ └── main.ml
├── dune-project
├── foo.opam
├── lib
│ ├── bar.ml
│ ├── dune
│ └── foo.ml
└── test
├── dune
└── foo.ml
4 directories, 9 files
code:dune-project
(lang dune 3.9)
(name foo)
(generate_opam_files true)
(source
(github username/reponame))
(authors "Author Name")
(maintainers "Maintainer Name")
(license LICENSE)
(package
(name foo)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(tags
(topics "to describe" your project)))
code:foo.ml
let x = 3
code:bar.ml
let x = 4
foo.mlの方のxはFoo.xで参照できる
code:output
utop # Foo.x;;
- : int = 3
でもbar.mlの方は予想に反する.
code:output
utop # Foo.Bar.x;;
Error: Unbound module Foo.Bar
utop # Bar.x;;
Error: Unbound module Bar
utop # Foo__Bar.x;;
- : int = 4
utop # Foo__.Bar.x;;
- : int = 4
これの何が気に入らないかというと,testからlibのものを使いたいときに,Foo.Bar.xではなくFoo__.Bar.xと書かないといけないところ.
code:test/dune
(test
(name foo)
(libraries foo))
code:test/foo.ml
let ()=print_int Foo.x;;
let ()=print_int Foo.Bar.x;;
let ()=print_int Foo__.Bar.x;;
code:dune test
File "test/foo.ml", line 2, characters 17-26:
2 | let ()=print_int Foo.Bar.x;;
^^^^^^^^^
Error: Unbound module Foo.Bar
まあFoo__.Bar.xとすれば利用できるけど,実際の使用感に合わせてFoo.Bar.xと書きたい.
ここの質問を読む限り,duneはまずFoo__Barを生成したあと,Foo.Barをそのモジュールのエイリアスにするらしい(バージョン1.11.3現在). →けどFoo.Barが存在しないことになっている.
Your system is basically replicating -for-pack but using a preprocessor.
とのことだが,
code:ocamlc --help|grep -A2 -- -for-pack
-for-pack <ident> Generate code that can later be `packed' with
ocamlc -pack -o <ident>.cmo
-g Save debugging information
というわけで,これが関係するのか正直わからない.
実際,
code:lib/dune
(library
(name foo)
(flags -for-pack))
としても,何も変わらなかった.
duneファイルの解説に書かれているように,(wrapped false)を指定すると,トップレベルでBarモジュールが使えるようになったが,明らかにやらないほうがいい.