Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe TROESTLER <debian00@tiscali.be>
To: gnu04@yahoo.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] how to write interface file for these two files?
Date: Mon, 28 Jun 2004 02:44:18 +0200 (CEST)	[thread overview]
Message-ID: <20040628.024418.15565414.debian00@tiscali.be> (raw)
In-Reply-To: <20040627230126.86986.qmail@web60905.mail.yahoo.com>

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


      reply	other threads:[~2004-06-28  0:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-27 23:01 Gu Nu
2004-06-28  0:44 ` Christophe TROESTLER [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040628.024418.15565414.debian00@tiscali.be \
    --to=debian00@tiscali.be \
    --cc=caml-list@inria.fr \
    --cc=gnu04@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox