caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Vincent Poirriez <Vincent.Poirriez@univ-valenciennes.fr>
To: caml-list@inria.fr
Cc: dorian.petit@univ-valenciennes.fr
Subject: [Caml-list] modules and objects
Date: Thu, 28 Nov 2002 19:14:40 +0100	[thread overview]
Message-ID: <20021128191440.587d1608.Vincent.Poirriez@univ-valenciennes.fr > (raw)

Hello list,

My non-important question is "why a module is not a first class
value? while objects are."
 I was playing with modules and objects, and I found funny that it's
possible to simulate the constructor new, just by using a functor
taking an empty module. 

module Void = struct end
module type Unit = sig end

module Build(M:Unit) = struct
 let r = ref 0
 let get () = !r
 let put i = r :=i
end

module type CONS = sig val get: unit -> int end
module type PROD = sig val put: int -> unit end

module Foo = Build(Void)
module Bar = Build(Void)
module FooC= (Foo:CONS)
module FooP= (Foo:PROD)

What remains impossible is:
 let lm = [FooP;FooC]  impossible

While with objects:
class build = object
val mutable r = 0
method get = r
method put i = r <- i
end

let foo = new build
let bar = new build

class virtual cons = object
 method  virtual get : int
end
class virtual prod = object
 method  virtual put : int -> unit
end
let fooc = (foo :> cons)
let foop = (foo :> prod)

 let lo = [foo;bar]

Is correct.

Vincent



-- 
courriel: vincent.poirriez@univ-valenciennes.fr  
tel: (33)[0]3 27 51 19 53 
Université de Valenciennes et du Hainaut-Cambrésis - Le Mont Houy
F-59313 Valenciennes cedex 9 - FRANCE
http://www.univ-valenciennes.fr/LAMIH/ROI/poirriez
-------------------
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


                 reply	other threads:[~2002-11-28 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='20021128191440.587d1608.Vincent.Poirriez@univ-valenciennes.fr ' \
    --to=vincent.poirriez@univ-valenciennes.fr \
    --cc=caml-list@inria.fr \
    --cc=dorian.petit@univ-valenciennes.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).