* How to define submodules
@ 2006-07-21 11:53 Jozef Kosoru
2006-07-21 12:01 ` [Caml-list] " Jean-Christophe Filliatre
0 siblings, 1 reply; 5+ messages in thread
From: Jozef Kosoru @ 2006-07-21 11:53 UTC (permalink / raw)
To: caml-list
Hello,
I'm trying to split my project files into several directories but I
can't figure out how to do it right.
Let's assume the following directory structure:
Kernel/Parser/pdf.ml
main.ml
and let's define the content of above files as:
~~~ Kernel/Parser/pdf.ml ~~~
let init () = print_string "hello world\n";;
~~~ main.ml ~~~
Kernel.Parser.Pdf.init ();;
~~~
OK, and then I want to compile it (within a root directory):
$ ocamlc -c Kernel/Parser/pdf.ml
$ ocamlc -I . Kernel/Parser/pdf.cmo main.ml -o app
File "main.ml", line 1, characters 0-22:
Unbound value Kernel.Parser.Pdf.init
Is this supposed to work somehow?
I know that most ocaml programs use a bit cumbersome approach and they
define long file names to emulate submodules. Eg.
Kernel/Parser/kernel_Parser_Pdf.ml
main.ml
~~~ main.ml ~~~
Kernel_Parser_Pdf.init ();;
~~~
And then:
$ ocamlc -c Kernel/Parser/kernel_Parser_Pdf.ml
$ ocamlc -I . -I Kernel/Parser/ \
Kernel/Parser/kernel_Parser_Pdf.cmo \
main.ml -o app
but that is rather inelegant.
But ANT project [1] uses this nice syntax. For
instance, there are files:
Engine/Evaluate.ml
Main/Main.ml
and Main.ml calls:
let pages = Engine.Evaluate.evaluate ast ...
is it some kind of language extension? I've noticed ANT uses a revised
OCaml syntax but there is no such a thing mentioned in its documentation
[2].
Thank you for any advice. Regards,
Jozef
[1] http://ant.berlios.de/
[2] http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html
--
jozef kosoru
http://zyzstar.kosoru.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How to define submodules
2006-07-21 11:53 How to define submodules Jozef Kosoru
@ 2006-07-21 12:01 ` Jean-Christophe Filliatre
2006-07-21 12:42 ` Jozef Kosoru
0 siblings, 1 reply; 5+ messages in thread
From: Jean-Christophe Filliatre @ 2006-07-21 12:01 UTC (permalink / raw)
To: Jozef Kosoru; +Cc: caml-list
Jozef Kosoru writes:
> OK, and then I want to compile it (within a root directory):
>
> $ ocamlc -c Kernel/Parser/pdf.ml
> $ ocamlc -I . Kernel/Parser/pdf.cmo main.ml -o app
>
> File "main.ml", line 1, characters 0-22:
> Unbound value Kernel.Parser.Pdf.init
>
> Is this supposed to work somehow?
No.
First, to compile main.ml you need to pass "-I Kernel/Parser" to the
compiler, because it needs to find the file pdf.cmi.
Second, in main.ml you have to write "Pdf.init" instead of
"Kernel.Parser.Pdf.init" because the directory structure is not turned
into a module structure in ocaml.
However, you can use the option -pack and -for-pack of the compiler to
pack several files as submodules of a new module; see the manual at
http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html
--
Jean-Christophe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How to define submodules
2006-07-21 12:01 ` [Caml-list] " Jean-Christophe Filliatre
@ 2006-07-21 12:42 ` Jozef Kosoru
2006-07-21 12:48 ` Nicolas Pouillard
2006-07-21 13:32 ` Chris King
0 siblings, 2 replies; 5+ messages in thread
From: Jozef Kosoru @ 2006-07-21 12:42 UTC (permalink / raw)
To: Jean-Christophe Filliatre; +Cc: caml-list
On Fri, Jul 21, 2006 at 14:01:26 +0200, Jean-Christophe Filliatre wrote:
> Jozef Kosoru writes:
> > OK, and then I want to compile it (within a root directory):
> >
> > $ ocamlc -c Kernel/Parser/pdf.ml
> > $ ocamlc -I . Kernel/Parser/pdf.cmo main.ml -o app
> >
> > File "main.ml", line 1, characters 0-22:
> > Unbound value Kernel.Parser.Pdf.init
> >
> > Is this supposed to work somehow?
>
> No.
>
> First, to compile main.ml you need to pass "-I Kernel/Parser" to the
> compiler, because it needs to find the file pdf.cmi.
>
> Second, in main.ml you have to write "Pdf.init" instead of
> "Kernel.Parser.Pdf.init" because the directory structure is not turned
> into a module structure in ocaml.
Yes, that was my second example. That's not exactly what I want.
> However, you can use the option -pack and -for-pack of the compiler to
> pack several files as submodules of a new module; see the manual at
> http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html
Thank you!
For the above example it's:
$ ocamlc -for-pack Kernel.Parser -c Kernel/Parser/pdf.ml
$ ocamlc -pack -o Parser.cmo -for-pack Kernel Kernel/Parser/pdf.cmo
$ ocamlc -pack -o Kernel.cmo Parser.cmo
$ ocamlc Kernel.cmo main.ml -o ap
Now the last thing is how to convince my OMakefile to do it
automatically.
Regards,
Jozef
--
jozef kosoru
http://zyzstar.kosoru.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How to define submodules
2006-07-21 12:42 ` Jozef Kosoru
@ 2006-07-21 12:48 ` Nicolas Pouillard
2006-07-21 13:32 ` Chris King
1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2006-07-21 12:48 UTC (permalink / raw)
To: Jozef Kosoru; +Cc: Jean-Christophe Filliatre, caml-list
On 7/21/06, Jozef Kosoru <zyzstar@uid0.sk> wrote:
> On Fri, Jul 21, 2006 at 14:01:26 +0200, Jean-Christophe Filliatre wrote:
> > Jozef Kosoru writes:
> > > OK, and then I want to compile it (within a root directory):
> > >
> > > $ ocamlc -c Kernel/Parser/pdf.ml
> > > $ ocamlc -I . Kernel/Parser/pdf.cmo main.ml -o app
> > >
> > > File "main.ml", line 1, characters 0-22:
> > > Unbound value Kernel.Parser.Pdf.init
> > >
> > > Is this supposed to work somehow?
> >
> > No.
> >
> > First, to compile main.ml you need to pass "-I Kernel/Parser" to the
> > compiler, because it needs to find the file pdf.cmi.
> >
> > Second, in main.ml you have to write "Pdf.init" instead of
> > "Kernel.Parser.Pdf.init" because the directory structure is not turned
> > into a module structure in ocaml.
>
> Yes, that was my second example. That's not exactly what I want.
>
> > However, you can use the option -pack and -for-pack of the compiler to
> > pack several files as submodules of a new module; see the manual at
> > http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html
>
> Thank you!
> For the above example it's:
>
> $ ocamlc -for-pack Kernel.Parser -c Kernel/Parser/pdf.ml
> $ ocamlc -pack -o Parser.cmo -for-pack Kernel Kernel/Parser/pdf.cmo
> $ ocamlc -pack -o Kernel.cmo Parser.cmo
> $ ocamlc Kernel.cmo main.ml -o ap
>
> Now the last thing is how to convince my OMakefile to do it
> automatically.
>
You can try YaM (http://perso.ens-lyon.fr/damien.pous/shared/ocaml/YaM/)
It handles directories and subdirectories very well using -pack options.
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How to define submodules
2006-07-21 12:42 ` Jozef Kosoru
2006-07-21 12:48 ` Nicolas Pouillard
@ 2006-07-21 13:32 ` Chris King
1 sibling, 0 replies; 5+ messages in thread
From: Chris King @ 2006-07-21 13:32 UTC (permalink / raw)
To: Jozef Kosoru; +Cc: caml-list
On 7/21/06, Jozef Kosoru <zyzstar@uid0.sk> wrote:
> Now the last thing is how to convince my OMakefile to do it
> automatically.
The in-development version of OMake (0.9.8) looks like it will contain
an OCamlPackage function... but until then, what I usually do is copy
the definition of OCamlLibrary from /usr/lib/omake/build/OCaml.om into
my project's OMakeroot, rename it, and modify it slightly to act like
OCamlPackage.
- Chris King
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-07-21 13:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-21 11:53 How to define submodules Jozef Kosoru
2006-07-21 12:01 ` [Caml-list] " Jean-Christophe Filliatre
2006-07-21 12:42 ` Jozef Kosoru
2006-07-21 12:48 ` Nicolas Pouillard
2006-07-21 13:32 ` Chris King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox