caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exported Types
@ 2002-06-26 17:15 Nicolas Cannasse
  2002-06-27  6:45 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Cannasse @ 2002-06-26 17:15 UTC (permalink / raw)
  To: OCaml

I got some problem using an "exported type" ( shared between modules ).
I know that I can avoid them by using polymorphic types but that'ld be nicer
without them.
I would also like of course to keep the files separated.

Here's a sample :

-- a.mli ---
type t (* exported *)

-- b.mli --
type t
val f : A.t -> t (* module B is using the type A.t but won't directly call
any A functions *)

-- b.ml --
type t = A.t (* quite stupid , but that's a sample ! *)
let f x = x

-- a.ml --
type t = int;;
ignore( B.f  (0:t) )
                 ---
(* This expression has type t = int but is here used with type A.t *)

I think this problem is quite standard, but I didn't find any clue on the
www
Any help will be welcomed

Nicolas Cannasse

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Exported Types
  2002-06-26 17:15 [Caml-list] Exported Types Nicolas Cannasse
@ 2002-06-27  6:45 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2002-06-27  6:45 UTC (permalink / raw)
  To: warplayer; +Cc: caml-list

From: "Nicolas Cannasse" <warplayer@free.fr>

> I got some problem using an "exported type" ( shared between modules ).
> I know that I can avoid them by using polymorphic types but that'ld be nicer
> without them.
> I would also like of course to keep the files separated.

The order of dependencies between modules is something strict: there
cannot be mutual recursion between two modules (at least, not
without doing some unsafe forward declarations using mutables).

Technically speaking, types do not depend on this order as long as you
provide .mli files (that is .mli and .ml order may be distinct), but
this is not a good idea to depend on it.
So I would rather suggest you forget about doing this.
What forces you so strongly to introduce such type level recursion?
Your example is too abstract to understand your goal.

In general, a reasonable approach would be to define A and B sharing
their types, and then define more abstract interfaces for them, to
call from outside.  With type abstraction, this should be possible.

But my experience of ML programming is that crafting interfaces is not
the point. The real point is using the right types.  Then you can
organize your code as you wish, anyway you cannot break it!

> -- a.mli ---
> type t (* exported *)
> 
> -- b.mli --
> type t
> val f : A.t -> t (* module B is using the type A.t but won't directly call
> any A functions *)
> 
> -- b.ml --
> type t = A.t (* quite stupid , but that's a sample ! *)
> let f x = x
> 
> -- a.ml --
> type t = int;;
> ignore( B.f  (0:t) )
>                  ---
> (* This expression has type t = int but is here used with type A.t *)

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-06-27  6:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-26 17:15 [Caml-list] Exported Types Nicolas Cannasse
2002-06-27  6:45 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).