caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile.starynkevitch@inria.fr>
To: Richard Jones <rich@annexia.org>, caml-list@inria.fr
Subject: Re: [Caml-list] Function forward declaration?
Date: Wed, 7 Apr 2004 19:26:48 +0200	[thread overview]
Message-ID: <20040407172648.GA12511@bourg.inria.fr> (raw)
In-Reply-To: <20040407141519.GA6618@redhat.com>

On Wed, Apr 07, 2004 at 03:15:19PM +0100, Richard Jones wrote:
> 
> The trouble seems to be that I have a perfectly practical and
> reasonable desire to see prototypes added to the language, because,
> believe it or now, it helps to solve some problems in the Real World.
> Now if there's some deep reason why it's actually impossible I would
> understand, but plenty of other languages (eg. C) seem to have
> prototypes and they get along just fine.

What I understand you call prototypes are signature items (or I
misunderstood your point). You can have use signatures and modules,
either by compiling both foo.mli & foo.ml (with the prototypes in
foo.mli & the implementations in foo.ml) or by having, inside your
compilation unit, a signature (or module type) and an structure (or
module).


[....]

> (Same, by the way, goes for a 'return' statement which OCaml is crying
> out for).

For your information, the revised syntax (provided by camlp4) does
have (IIRC) a return keyword (but I don't remember more, and I never
used it).


Regarding this thread, a useful trick (somehow a hack, but used in the
compiler itself) is to declare a reference to a function initialised
to a function throwing an exception:

   (** in foo.mli *)

   val rf: (int -> string) ref

   (** in foo.ml *)

   let rf = ref ((fun x -> failwith "rf not yet implemented") 
                : (int -> string))

   (* in a bar.ml *)

   Foo.rf := (fun x -> Printf.sprintf "the real rf %d" x);;

this trick is needed e.g. when two modules are mutually recursive, eg
if a function of foo calls a function of bar which calls the first
function of foo. (In the compiler, you can find such an instance -
Env;check_modtyping_inclusion is a reference to
Includemod.check_modtype_inclusion - in directory caml/typing/ )

Regards.
-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - INRIA Rocquencourt
http://cristal.inria.fr/~starynke --- all opinions are only mine 

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


  parent reply	other threads:[~2004-04-07 17:27 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-06 12:14 Timo.Tapiola
2004-04-06 12:20 ` Andrew Birkett
2004-04-06 12:37 ` Remi Vanicat
2004-04-06 13:00   ` Issac Trotts
2004-04-06 12:53 ` Correnson Loïc
2004-04-06 15:14   ` skaller
2004-04-06 17:39   ` brogoff
2004-04-06 17:53     ` Richard Jones
2004-04-06 19:28       ` Marcin 'Qrczak' Kowalczyk
2004-04-06 22:37         ` Jon Harrop
2004-04-07  2:18         ` skaller
2004-04-07  6:01         ` Nicolas Cannasse
2004-04-07  7:31           ` Marcin 'Qrczak' Kowalczyk
2004-04-07 16:40             ` brogoff
2004-04-07 13:52           ` skaller
2004-04-07 14:15             ` Richard Jones
2002-01-03 15:21               ` Issac Trotts
2004-04-07 15:51               ` skaller
2004-04-07 16:41                 ` Richard Jones
2004-04-07 17:31                   ` Remi Vanicat
2004-04-07 17:36                     ` Richard Jones
2004-04-07 17:54                       ` Marcin 'Qrczak' Kowalczyk
2004-04-07 19:27                     ` skaller
2004-04-07 20:24                       ` Christopher Dutchyn
2004-04-07 18:04                   ` Benjamin Geer
2004-04-07 19:21                   ` skaller
2004-04-07 16:52               ` Shawn Wagner
2004-04-07 17:26               ` Basile Starynkevitch [this message]
2004-04-07 17:46                 ` Marcin 'Qrczak' Kowalczyk
2004-04-07 18:03                   ` Kenneth Knowles
2004-04-07 18:44                 ` Christopher Dutchyn
2004-04-07 14:24             ` Ville-Pertti Keinonen
2004-04-07 15:12               ` skaller
2004-04-06 12:58 ` Jean-Christophe Filliatre
2004-04-06 17:26 ` Christopher Dutchyn

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=20040407172648.GA12511@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /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;
as well as URLs for NNTP newsgroup(s).