Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] how to write interface file for these two files?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe TROESTLER <debian00@t...>
Subject: Re: [Caml-list] how to write interface file for these two files?
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