List Info

Thread: "ocaml_beginners"::[] Trouble with passing types between modules




"ocaml_beginners"::[] Trouble with passing types between modules
user name
2006-11-17 04:47:30

1) Individual modules aren't recursive, so A can't reference B, which
references A
2) anything you declare in an .mli file must be present in the
associated .ml file (if there is one)

So in your case, History.take_snapshot depends on the type in Model,
and Model.snapshot depends on History.take_snapshot.

Moving the type declaration for Model into a separate module which
only defines types, for instance, will break the recursive
dependencies.

Jonathan

On 11/17/06, doeweyahewe < doeweyahewe%40yahoo.com.sg">doeweyaheweyahoo.com.sg> wrote:
&gt; Hi there,
&gt;
> I'm using OCaml to do some modelling work, and I've come across a
> problem. My model is implemented in model.ml(i) and I have some
> analysis code in query.ml(i). Here's the basic problem:
>
> Model.mli
> =========
> type model = ...
>
> History.mli
> ===========
> type snapshot = ...
>
> val take_snapshot : Model.model -> snapshot
>
> Model.ml
> ========
> let snapshot = take_snapshot some_model in ...
>
> Compiler Error
>; ==============
> "This expression [some_model] has type model but is here used with
> type Model.model"
&gt;
> For some reason, the OCaml compiler doesn't recognise that
> Model.model is exactly the same type as model, inside the Model
>; module. How can I get around this behaviour?
>
>; Many thanks in advance for your time and any advice,
&gt; Rob Moss
>
>
>;
>
&gt; Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
> The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
> Yahoo! Groups Links
>;
>
&gt;
>
&gt;

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Trouble with passing types between modules
user name
2006-11-20 14:15:13

Yeah, I got confused -- I thought that you could have
recursive modules, as long as there were no recursive
definitions. It's all taken care of, thanks to the
advice I received on this group.

Thankyou very much for the help

cheers,
Rob

--- Jonathan Roewen < jonathan.roewen%40gmail.com">jonathan.roewengmail.com> wrote:
&gt; 1) Individual modules aren't recursive, so A can't
>; reference B, which references A
> 2) anything you declare in an .mli file must be
> present in the associated .ml file (if there is one)
>
> So in your case, History.take_snapshot depends on
> the type in Model,
&gt; and Model.snapshot depends on History.take_snapshot.
>
> Moving the type declaration for Model into a
> separate module which
>; only defines types, for instance, will break the
> recursive
> dependencies.
>
> Jonathan
>
> On 11/17/06, doeweyahewe < doeweyahewe%40yahoo.com.sg">doeweyaheweyahoo.com.sg>
> wrote:
&gt; > Hi there,
&gt; >
> > I'm using OCaml to do some modelling work, and
> I've come across a
> > problem. My model is implemented in model.ml(i)
> and I have some
> > analysis code in query.ml(i). Here's the basic
>; problem:
> >
> > Model.mli
> > =========
> > type model = ...
> >
> > History.mli
> > ===========
> > type snapshot = ...
> >
> > val take_snapshot : Model.model -> snapshot
> >
> > Model.ml
> > ========
> > let snapshot = take_snapshot some_model in ...
> >
> > Compiler Error
>; > ==============
> > "This expression [some_model] has type model but
> is here used with
> > type Model.model"
&gt; >
> > For some reason, the OCaml compiler doesn't
&gt; recognise that
> > Model.model is exactly the same type as model,
&gt; inside the Model
>; > module. How can I get around this behaviour?
> >
> > Many thanks in advance for your time and any
> advice,
&gt; > Rob Moss
> >
> >
> >
> >
> > Archives up to November 11, 2006 are also
> downloadable at
>
http://www.connettivo.net/cntprojects/ocaml_beginners/
> > The archives of the very official ocaml list (the
> seniors' one) can be found at http://caml.inria.fr
> > Attachments are banned and you're asked to be
> polite, avoid flames etc.
> > Yahoo! Groups Links
>; >
> >
> >
> >
> >
>
>
> Archives up to November 11, 2006 are also
> downloadable at
>
http://www.connettivo.net/cntprojects/ocaml_beginners/
> The archives of the very official ocaml list (the
> seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be
> polite, avoid flames etc.
> Yahoo! Groups Links
>;
> (Yahoo! ID required)
>
> mailto: ocaml_beginners-fullfeatured%40yahoogroups.com">ocaml_beginners-fullfeaturedyahoogroups.com
&gt;
>
>
>


____________________________________________________
Yahoo! Singapore Answers
Real people. Real questions. Real answers. Share what you know at http://answers.yahoo.com.sg

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )