caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] Basic question about modules
@ 2004-03-23 21:59 Tim Docker
  2004-03-23 22:33 ` Kenneth Knowles
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Docker @ 2004-03-23 21:59 UTC (permalink / raw)
  To: Kenneth Knowles; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1141 bytes --]

> Well, you can use `ocamlc -i' to initially create the .mli file,
> or inspect its output for help.

Thanks - this is good. Looking at the output, I see that the entire
signature for the string map is present:

 | module StringMap :
 |   sig
 |     type key = String.t
 |     and 'a t = 'a Map.Make(String).t
 |     val empty : 'a t
 |     val add : key -> 'a -> 'a t -> 'a t
 |     val find : key -> 'a t -> 'a
 |     val remove : key -> 'a t -> 'a t
 |     val mem : key -> 'a t -> bool
 |     val iter : (key -> 'a -> unit) -> 'a t -> unit
 |     val map : ('a -> 'b) -> 'a t -> 'b t
 |     val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
 |     val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
 |   end
 | type info = int list StringMap.t
 | and named_values = { details : info; }

Do I actually have to duplicate the above signature for the StringMap
as shown above in my own mli file (and other similar types).
This seems pretty heavy handed.

At the end of the day I am just attempting to define some datatypes
that include maps of various types created with the Map.Make functor.

Thanks,

Tim


[-- Attachment #2: Type: text/html, Size: 2063 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [Caml-list] Basic question about modules
@ 2004-03-23 20:42 Tim Docker
  2004-03-23 21:02 ` Kenneth Knowles
  2004-03-23 21:12 ` Matthieu Dubuget
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Docker @ 2004-03-23 20:42 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1032 bytes --]

Having used haskell, I'm getting to grips with the core ocaml
language, but am somewhat confused by modules.

If I compile a simple file, X.ml:

 | module StringMap = Map.Make (String)
 | 
 | type info = int list StringMap.t
 |
 | type named_values = {
 |    details : info
 | }
 |
 | ..... other stuff ....

then ocamlc will automatically build a x.cmi file that exports
everything. I can use this from another file Y.ml:

 | let x = X.StringMap.empty;;
 |
 | let y = { X.details=X.StringMap.add "xxx" [1;2;3] x }

although the X.StringMap.fn syntax seems a bit unwieldy.

If I want to restrict what gets exported, I have to
write an x.mli file. Whilst I've written mli files for simple
types and functions, I'm at a loss as how to write the contents
of the mli file that corresponds to the one automatically generated
above (specifically the StringMap bit).

A pointer would be much appreciated, either how to write the .mli
file, or a generally better way of doing this stuff.

Thanks,

Tim


[-- Attachment #2: Type: text/html, Size: 1630 bytes --]

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

end of thread, other threads:[~2004-03-23 22:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-23 21:59 [Caml-list] Basic question about modules Tim Docker
2004-03-23 22:33 ` Kenneth Knowles
  -- strict thread matches above, loose matches on Subject: below --
2004-03-23 20:42 Tim Docker
2004-03-23 21:02 ` Kenneth Knowles
2004-03-23 21:12 ` Matthieu Dubuget

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).