From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Tiphaine.Turpin@free.fr, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OO programming
Date: Wed, 27 Feb 2008 10:37:33 +0900 (JST) [thread overview]
Message-ID: <20080227.103733.43387508.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <47C4AE08.5000604@free.fr>
From: "Tiphaine.Turpin" <Tiphaine.Turpin@free.fr>
> First, my desired use of objects is not (reduced to) programming a gui.
> I can imagine that, in guis, the actions that may be invoked on objects
> or that may originate from them are just signals with rather simple
> types, which form a simple case of object communication for which action
> connection is enough, but when it comes to using objects to model the
> objects of the application domain, stronger links (i.e., fields) are
> sometimes natural. Note that, in class diagrams, links between classes
> are one of the most basic concepts.
My point was that it's not because it is a good concept that it is
necessarily a good programming technique. That is, you might want to
right your class diagram with links between classes, but use an
indirection at the connection level in your implementation, if it
makes things simpler. I see no contradiction there. But as I wrote in
my previous mail, OO people often prefer to have their concepts
directly apparent in their programs.
> > But I think your disagreement lies at a different level: OO
> > programmers often want to express their own view of things directly
> > into the language.
> Yes. Clearly, I want the abstractions, patterns, etc. I have in mind to
> be expressed themselves as language objects, and not just their
> "instanciation". Isn't this the very goal of high-level languages after
> all ?
Yes, but the ocaml approach is to define entities independently, and
let types handle the interconnections. This does not fit well with
class diagrams. So if you want to keep your class diagram apparent,
you need painful contorsions.
Note also that your original goal, being able to extend families of
classes at the type level, is an active research area. When ocaml was
created, there was no OO language able to do it explicitly, or even
implicitly (as ocaml does). Now you might have your chance with Scala
or gBeta.
> > Klaus Ostermann. Nominal and structural subtyping in component-based
> > programming. Journal of Object Technology, 7(1):121 - 145, 2008.
> >
> An interesting reading. The expressive power that he adds to nominal
> subtyping gives me more arguments to consider structural subtyping not
> very usefull (but I understand that structural is much more consistent
> with everything else in ocaml).
Not really. He build his nominal subtyping as an extension of
structural subtyping. And I'm personally not sure that the nominal
part gets him much (out of better error messages, which do matter)
> >> Hence my question: does anyone knows a way of combining the reusability
> >> of sets of related classes with a more modular (type/consistency)-checking ?
> >>
> >
> > I'm not sure whether it helps, but I attach here the same example of
> > observer pattern as in the tutorial,
> which tutorial ?
Section 5.3 of the reference manual, which is a variation on the one
you were mentionning.
> > but without using type parameters. They are replaced by private row types.
> >
> which is very verbose (having to explicitely write class types), and I'm
> not sure I understand the benefits of doing this.
Verbose indeed. I didn't say this was the right way to do it, just
that it lets you express more relations in the interfaces.
> > Ideally, one would like to check coherence too by writing
> > module rec Check : S' = Window(Check)
> > Unfortunately, this doesn't seem to work currently. I'm not yet sure
> > whether this is a bug or a limitation of recursive modules.
> >
> If the typing of recursive modules just types the body of each module in
> the environment given by the declared module types of all modules
> involved in the recursive definition, then this cannot work, since
> Window(Check) would have to be of type S' for any Check : S', which is
> clearly false (e.g. Check = struct ... type observer = <foo: unit;
> notify : ...).
No, the typing of recursive modules is much more clever, otherwise it
wouldn't be useful. So, conceptually, this could work.
For instance, if you drop the ability to add methods to the observer,
the check goes through:
module type S' = sig
type event = private [> `Move]
type subject = private <draw: unit; ..>
type observer = <notify: subject -> event -> unit>
end
module Window(X:S') = struct
module AX = Any(X)
type event = X.event
class observer =
object
inherit AX.observer
method notify s e = s#draw
end
let count = ref 0
class virtual subject =
let id = count := succ !count; !count in
object (self)
inherit AX.subject
val mutable position = 0
method identity = id
method move x = position <- position + x; self#notify_observers `Move
method draw = Printf.printf "{Position = %d}\n" position;
end
end
module rec Check : S' = Window(Check)
This way you can see that subject and observer are compatible without
providing concrete instances.
However, when the observer and subject have both extensible types,
there seems to be an interaction between nominal and structural types,
and the knot cannot be tied.
> As for extension, I'm fully satisfied. But the verbosity level is
> annoying for scalability...
Well, yes, that's always the problem with functors...
Jacques Garrigue
next prev parent reply other threads:[~2008-02-27 1:37 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-21 9:31 Tiphaine Turpin
2008-02-21 9:42 ` [Caml-list] " Erik de Castro Lopo
2008-02-21 13:38 ` Remi Vanicat
2008-02-24 16:33 ` [Caml-list] " Dirk Thierbach
2008-02-25 9:23 ` Tiphaine.Turpin
2008-02-25 15:48 ` Edgar Friendly
2008-02-25 16:02 ` Berke Durak
2008-02-25 20:12 ` Dirk Thierbach
2008-02-25 20:51 ` Tiphaine.Turpin
2008-02-25 23:03 ` Dirk Thierbach
2008-02-25 20:10 ` Dirk Thierbach
2008-02-25 21:49 ` Tiphaine.Turpin
2008-02-25 23:07 ` Dirk Thierbach
2008-02-29 14:22 ` Tiphaine.Turpin
2008-02-26 6:17 ` Jacques Garrigue
2008-02-26 9:36 ` Julien Signoles
2008-02-27 0:25 ` Tiphaine.Turpin
2008-02-27 1:37 ` Jacques Garrigue [this message]
2008-02-28 8:34 ` Keiko Nakata
2008-02-28 13:30 ` Andrej Bauer
2008-02-28 15:18 ` Keiko Nakata
2008-02-28 16:02 ` Edgar Friendly
2008-02-29 14:35 ` Tiphaine.Turpin
2008-02-29 15:58 ` Keiko Nakata
2008-03-03 9:40 ` Tiphaine.Turpin
2008-03-03 10:20 ` Jacques Garrigue
2008-03-03 10:30 ` Tiphaine.Turpin
2008-03-03 15:18 ` Keiko Nakata
2008-03-03 19:25 ` Tiphaine Turpin
2008-03-04 14:00 ` Keiko Nakata
2008-02-27 7:40 ` Dirk Thierbach
2008-02-27 14:04 ` Tiphaine.Turpin
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=20080227.103733.43387508.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=Tiphaine.Turpin@free.fr \
--cc=caml-list@yquem.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