caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* CSL modules
@ 1996-03-01 15:24 Guy.Cousineau
  1996-03-04 14:05 ` Xavier Leroy
  0 siblings, 1 reply; 5+ messages in thread
From: Guy.Cousineau @ 1996-03-01 15:24 UTC (permalink / raw)
  To: caml-list; +Cc: cousineau




My problem is the following:
I have a module A which defines a concrete type ta
and a variable xa of type ta.
I have a module B which defines a concrete type tb
and a variable xb  of type tb.

I would like to build a fonctor F such that  C=F(A,B)  "reexports"
the  types and variables of A and B but with tb now being an abstract type.
and ta remaining a concrete type .
Moreover,  I want  C.xa  to be a value of type C.ta and not a value of type A.ta
which would be easy. The reason for that is that I do not want
the users of my programs to see modules A and B but only module C.
In other words, I try to use CSL modules to perform what was
possible in Caml Light using the trick decribed in the section 7.3
of the manual  under the title "turning code into a library".

I was hoping to be able to do it more cleanly in CSL.
But this seems to be impossible or am I wrong?

--Guy 








^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSL modules
  1996-03-01 15:24 CSL modules Guy.Cousineau
@ 1996-03-04 14:05 ` Xavier Leroy
  1996-03-05  9:03   ` Wolfgang Lux
  1996-03-05  9:55   ` Christophe Raffalli
  0 siblings, 2 replies; 5+ messages in thread
From: Xavier Leroy @ 1996-03-04 14:05 UTC (permalink / raw)
  To: Guy.Cousineau; +Cc: caml-list


> I would like to build a fonctor F such that  C=F(A,B)  "reexports"
> the  types and variables of A and B but with tb now being an abstract type.
> and ta remaining a concrete type .
> Moreover, I want C.xa to be a value of type C.ta and not a value of
> type A.ta which would be easy. The reason for that is that I do not
> want the users of my programs to see modules A and B but only module
> C.

This is easily done using a signature constraint to specify exactly
how much of C should remain visible:

module type SIGA =
  sig
    type ta = A | B of int
    val xa : ta
  end
module type SIGB =
  sig
    type tb = C | D of string
    val xb : tb
  end
module type SIGC =
  sig
    type ta = A | B of int      (* concrete *)
    type tb                     (* abstract *)
    val xa : ta
    val xb : tb
  end
module F(A: SIGA)(B: SIGB) =
  (struct
     type ta = A.ta = A | B of int
     type tb = B.tb
     let xa = A.xa
     let xb = B.xb
   end : SIGC)
module C = F(A)(B)

Notice the type definition "type ta = A.ta = A | B of int", which
keeps C.ta compatible with A.ta while re-exporting the constructors A
and B, which are now part of C. An alternate definition would be:

module type SIGC =
  sig
    type ta = A.ta              (* concrete *)
    type tb                     (* abstract *)
    val xa : ta
    val xb : tb
  end
module F(A: SIGA)(B: SIGB) =
  (struct
     type ta = A.ta
     type tb = B.tb
     let xa = A.xa
     let xb = B.xb
   end : SIGC)
module C = F(A)(B)

It is also correct, but not as good because A is not completely
hidden: the constructors of C.ta still come from A, not C. 

- Xavier Leroy





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSL modules
  1996-03-04 14:05 ` Xavier Leroy
@ 1996-03-05  9:03   ` Wolfgang Lux
  1996-03-06  9:28     ` Xavier Leroy
  1996-03-05  9:55   ` Christophe Raffalli
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Lux @ 1996-03-05  9:03 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: Guy.Cousineau, caml-list


> This is easily done using a signature constraint to specify exactly
> how much of C should remain visible:
> 
> module type SIGA =
>   sig
>     type ta = A | B of int
>     val xa : ta
>   end
> module type SIGB =
>   sig
>     type tb = C | D of string
>     val xb : tb
>   end
> 

[ alternate (and better) definition of SIGC and F deleted]

> module type SIGC =
>   sig
>     type ta = A.ta              (* concrete *)
>     type tb                     (* abstract *)
>     val xa : ta
>     val xb : tb
>   end
> module F(A: SIGA)(B: SIGB) =
>   (struct
>      type ta = A.ta
>      type tb = B.tb
>      let xa = A.xa
>      let xb = B.xb
>    end : SIGC)
> module C = F(A)(B)
> 

Being curious I tried this and got an error from CSL 1.14, which I
really don't understand. After defining SIGA and SIGB and the
following two sample modules

module A : SIGA =
  struct
    type ta = A | B of int
    let xa = B 4
  end
module B : SIGB =
  struct
    type tb = C | D of string
    let xb = D "hello"
  end

I can define SIGC, but when I enter the definition of F, CSL returns
the following error:

Signature mismatch:
Modules do not match:
  sig type ta = A.ta type tb = B.tb val xa : A.ta val xb : B.tb end
is not included in
  SIGC
Type declarations do not match:
  type ta = A.ta
is not included in
  type ta = A.ta

Any clues?

Wolfgang

----
Wolfgang Lux
WZH Heidelberg, IBM Germany             Internet: lux@heidelbg.ibm.com
+49-6221-59-4546                        VNET:     LUX at HEIDELBG
+49-6221-59-3500 (fax)	                EARN:     LUX at DHDIBMIP





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSL modules
  1996-03-04 14:05 ` Xavier Leroy
  1996-03-05  9:03   ` Wolfgang Lux
@ 1996-03-05  9:55   ` Christophe Raffalli
  1 sibling, 0 replies; 5+ messages in thread
From: Christophe Raffalli @ 1996-03-05  9:55 UTC (permalink / raw)
  To: Xavier.Leroy; +Cc: Guy.Cousineau, caml-list



I have a question about modules:

Would it be possible to partially hide constructor:

It would be nice to be able to match a constructor but not to construct it or
vice versa (use full for exceptions for instance)

----
Christophe Raffalli
Dept. of Computer Sciences
Chalmers University of Technology

URL: http://www.logique.jussieu.fr/www.raffalli




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSL modules
  1996-03-05  9:03   ` Wolfgang Lux
@ 1996-03-06  9:28     ` Xavier Leroy
  0 siblings, 0 replies; 5+ messages in thread
From: Xavier Leroy @ 1996-03-06  9:28 UTC (permalink / raw)
  To: Wolfgang Lux; +Cc: caml-list


> Being curious I tried this and got an error from CSL 1.14, which I
> really don't understand.

My code was wrong, I just confused the formal parameter "A" of the
functor with the global module "A". CSL just complains that these two
are not a priori the same module (when typing the body of the
functor).

What I should have written is:

module F(A: SIGA)(B: SIGB) =
  (struct
     type ta = A.ta
     type tb = B.tb
     let xa = A.xa
     let xb = B.xb
   end :
   sig
    type ta = A.ta              (* concrete *)
    type tb                     (* abstract *)
    val xa : ta
    val xb : tb
  end)
   
My apologies for the confusion.

- Xavier Leroy





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-03-06 11:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-01 15:24 CSL modules Guy.Cousineau
1996-03-04 14:05 ` Xavier Leroy
1996-03-05  9:03   ` Wolfgang Lux
1996-03-06  9:28     ` Xavier Leroy
1996-03-05  9:55   ` Christophe Raffalli

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