caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] how to write interface file for these two files?
@ 2004-06-27 23:01 Gu Nu
  2004-06-28  0:44 ` Christophe TROESTLER
  0 siblings, 1 reply; 2+ messages in thread
From: Gu Nu @ 2004-06-27 23:01 UTC (permalink / raw)
  To: caml-list

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

Hi, all 
 
I have a question on writing the interface file.
 
A.ml
 
type t = { x: int; y: int};;
let f c = c.x + c.y;;
 
B.ml
 
let val = {A.x =1 ; A.y = 2};;
A.f val;;
open A;;
f val;;
 
How to write a interface file for B.ml, 
in which no functions are explicitly defined?
 
Thanks a lot!
 
Andy

		
---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

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

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

* Re: [Caml-list] how to write interface file for these two files?
  2004-06-27 23:01 [Caml-list] how to write interface file for these two files? Gu Nu
@ 2004-06-28  0:44 ` Christophe TROESTLER
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe TROESTLER @ 2004-06-28  0:44 UTC (permalink / raw)
  To: gnu04; +Cc: caml-list

On Sun, 27 Jun 2004, Gu Nu <gnu04@yahoo.com> wrote:
> 
> I have a question on writing the interface file.

Just use the output of "ocamlc -i file.ml" as a first version (this,
in fact, is just the interface you get if no .mli file is present).
You can of course then refine it, not exporting certain values, making
certain types abstract...

> A.ml
>  
> type t = { x: int; y: int};;
> let f c = c.x + c.y;;

$ ocamlc -i a.ml 
type t = { x : int; y : int; }
val f : t -> int

> B.ml
>  
> let val = {A.x =1 ; A.y = 2};;
> A.f val;;
> open A;;
> f val;;

Note that "val" is a reserved keyword -- you cannot use it as a
variable name.  Also, I think it is not nice to use ";;" to discard a
returned value.  Rather say it explicitely with "let _ =".  That gives

let pt = {A.x = 1 ; A.y = 2}
let _ = A.f pt
open A
let _ = f pt

$ ocamlc -i  b.ml
val pt : A.t

The values that are not given a name are not present in the signature
-- pretty natural, isn't it.

Hope it helps,
ChriS

-------------------
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:[~2004-06-28  0:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-27 23:01 [Caml-list] how to write interface file for these two files? Gu Nu
2004-06-28  0:44 ` Christophe TROESTLER

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