Message-Id: <9607221531.AA06681@elrond.uc3m.es>
Date: Mon, 22 Jul 1996 17:19:49 -0500
From: "Francisco J. Valverde" <fva@ing.uc3m.es>
Subject: Some questions about the module system...
To: caml-list@pauillac.inria.fr
Hello mailing list,
here are some questions I would like to pose the system implementors
concerning the module system in O'Caml. The mail is quite lengthy, and I
apologise in case somebody else has asked the same... (I have been unable t=
o
look up the question in the mailing archives).
1) is there any reason (unclear semantics, scope-holing, etc.) why the O'Ca=
ml
module system won't allow an "include <signature>" feature? I keep bumping
into it when I try to write module hyerarchies (or adapt ML code from texts=
;) ).
What I am asking about is a nice "feature" for doing:
module type ELEMENT =3D
sig
type t
val format : t -> unit
end;;
module type ORDER =3D
sig
include ELEMENT
val leq : t -> t -> bool
end;;
module type DOMAIN =3D
sig
include ORDER
val bottom: t
end;;
(...and so on and so forth), instead of writing "all that code again".
b) My second question concerns module coercion by means of module signature=
s.
Sharing constraints between module types is really necessary for code
abstraction, but I found "value aliasing" really useful as well (I don't
know the exact term for the feature so I will describe it).
Suppose you have this priority queue functor requesting an ORDER on values =
of
the type shown above:
module MakePQueue =3D (struct ... end: (O: ORDER) -> PQUEUE);;
and a module implementing NODEs in a graph with data about the distance fro=
m
the node to a "root" and an accumulated value describing another distance
measure:
module NODE =3D
sig
type node =3D{ depth: int; dist: int; ...}
..
end;;
Now, I would like to implement 2 different searching strategies namely
DepthFirst and heuristic search ( "A" strategy someone would say), for
which I need to consider two different orders (take my word for it):
value less_depth: node -> node -> bool=09(* depthFirst order *)
value less_dist: node -> node -> bool=09(* A* search order *)
How could I view NODE as these two different orders so that MakePQueue does=
n't
complain? Answer: *alias* any of the orders to the order defined in ORDER:
(* this won't work in O'Caml 1.01 *)
module DepthFirstPQueue =3D
MakePQueue (Node: NODE with t =3D node (* and val leq =3D less_depth *));=
;
module BestFirstPQueue =3D
MakePQueue (Node: NODE with t =3D node (* and val leq =3D less_dist *));;
Unless I got it wrong all you can do for now is write TWO module signatures=
, say
NODE1 and NODE2, in which you define the required order with the adequate n=
ame,
that is to say "leq". *You* have to keep consistency between the rest of th=
e primitives
on your own, and this is really... burdensome!
My feeling is that implementing this amounts to *rewriting* "leq" as
"less_dist", but this is merely a sintactic procedure and I am not sure
how would the semantics be affected: are modules just "environments" as
in ML, or do we have a more comvoluted semantica which rules out this
behaviour?
I would like any comments about this, or other (more imaginative) ways
around these *burdensome* ways of writing code...
Francisco J. Valverde-Albacete
'Area de Tecnolog'ia Electr'onica
Dept. de Ingenier'ia (Area de Teconolog'ia Electr'onica)
Univ. Carlos III de Madrid
ESPA=D1A (Spain)