Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] fermer un listbox, (ou detruire )
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: [Caml-list] Pb with type constraints in module

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