caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
Cc: caml-list@inria.fr
Subject: [Caml-list] Pb with type constraints in module
Date: Tue, 11 Feb 2003 22:05:05 -0500	[thread overview]
Message-ID: <3E49B9E1.3060106@univ-savoie.fr> (raw)
In-Reply-To: <F29KTmtFynAanqdq4Y100045221@hotmail.com>

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


Is there a good reason to have this in the grammar
mod-constraint ::=
   type [type-parameters]  typeconstr =  typexpr
| module module-path =  extended-module-path

instead of
mod-constraint ::=
   type typedef
| module module-path =  extended-module-path

Here is an example where this is useful:

Lets say you have  a nice module type and functor:

--
module type Ord =
   sig
	type t
	val compare : t -> t -> int
   end

module F(G:Ord) =
   struct
	type t = Empty | Node of G.t * t * t
	let compare = ... the code you want ...
   end
--

in a .mli you may want to write

--
module F : functor (G:Ord) -> Ord
   with type t = Empty | Node of G.t * t * t
--

And this is not legal because "with type" take a typeexpr and not a 
typedef. This is not very natural, bacause you have to move the 
definition of t outside F like in
--
type 'a tree = Empty | Node of 'a * 'a tree * 'a tree
module F(G:Ord) =
   struct
	type t = G.t tree
	let compare = ... the code you want ...
   end
--

in a .mli you can now write
--
type 'a tree = Empty | Node of 'a * 'a tree * 'a tree
module F : functor (G:Ord) -> Ord with type t = G.t tree
--

The same happends if you use recursive type
--
module F : functor (G:Ord) -> Ord with type t = (G.t * t) list
--
is not legal either.

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature
---------------------------------------------

[-- Attachment #2: Type: application/pgp-signature, Size: 252 bytes --]

  reply	other threads:[~2003-02-12  8:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-11 20:02 [Caml-list] fermer un listbox, (ou detruire ) deerf hal
2003-02-12  3:05 ` Christophe Raffalli [this message]
2003-02-19 11:00   ` [Caml-list] Pb with type constraints in module Tom Hirschowitz
2003-02-19 11:49     ` Tom Hirschowitz

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=3E49B9E1.3060106@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@inria.fr \
    /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).