Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Damien Pous <Damien.Pous@ens-lyon.fr>
To: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] functors and objects'
Date: Tue, 03 Feb 2004 21:26:25 +0100 (CET)	[thread overview]
Message-ID: <1075839985.402003f1527cb@mouette.ens-lyon.fr> (raw)
In-Reply-To: <20040203193958.GA9048@swordfish>

En réponse à Matt Gushee <mgushee@havenrock.com>:

> On Tue, Feb 03, 2004 at 07:06:35PM +0100, Damien wrote:
> > 	type t :> o (* sigh... *)
>
> The first problem is that you're mixing type declarations and class
> casts ... not a hard mistake to make, since the class cast syntax is a
> bit confusing, and doesn't seem to be explained very well anywhere.
of course, this was not "real OCaml code" :)
I just wanted to express the fact that my functor R has to accept any module M
defining an object type `t' with at least a method `react'
(that is, t :> o)

> > module R(M: O') = 
> > struct
> > 	include R(M)
> 
> I don't see how this can work, because this module R takes an argument
> of type O', whereas the other R (do you really want to give them the
> same name?) takes an argument of type O. Regardless of their contents,
> they are different interfaces and thus not interchangeable. 
since o' :> o, M: O' should be a valid candidate for R...

> There's undoubtedly a way to achieve the result you want, but I don't 
> really understand what you are trying to do. 

the following correct code does partially what I want :

module type O = sig 
  type t
  val send: [<`React] -> t -> unit
end
module R(M: O) = struct
  let l = ref []
  let register (o: M.t) = l := o :: !l
  let react() = List.iter (M.send `React) !l
end

module type O' = sig
  type t
  val send: [<`React|`Render] -> t -> unit
end
module R'(M: O') = struct
  include R(M)   (* <-- "subtyping" is automagically done *)
  let render() = List.iter (M.send `Render) !l
end

but I am partially re-encoding objects with modules and variants,
and this encoding becomes quite ugly when it comes to _real_ objects
(with inheritance, virtual methods...)


> Do you actually have a specific goal in mind, or are you just experimenting?

both !

I am working on a project that use a "Reactor" where a lots of "Objects" react.
This project is cut into three layers :
  Base       reactor and objects (generic)
  Meaningful reactor and objects (objects really react)
  Rendered   reactor and objects (Gtk, maybe GL some day)

Currently both reactor and objects are "OCaml objects", but the project only use 
_one_ instance of the rendered reactor class. Thus I am wondering how I could
turn it into a module...
This module has to be defined incrementally : Base, Meaningful, Rendered.
but at the Base level, the final type of contained objects is unknown,
whence the need for a functor.
(with objects, this is done with parametrized classes)

Since objects really need to be "objects" (late binding), 
I cannot turn both objects and reactor into modules (or at least in a beautiful way)

arf...

damien

-------------------
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:[~2004-02-04 14:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-03 18:06 [Caml-list] functors and objects Damien
2004-02-03 19:37 ` Matt Gushee
2004-02-03 19:39 ` [Caml-list] functors and objects' Matt Gushee
2004-02-03 20:26   ` Damien Pous [this message]
2004-02-04  2:57 ` [Caml-list] functors and objects Jacques Garrigue
2004-02-05  8:55   ` Damien
2004-02-05  9:18     ` Jacques Garrigue
2004-02-05 13:45       ` Damien
2004-02-06  1:30         ` Jacques Garrigue

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=1075839985.402003f1527cb@mouette.ens-lyon.fr \
    --to=damien.pous@ens-lyon.fr \
    --cc=caml-list@pauillac.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