Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: newton@MIT.EDU
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Is there a compact syntax for masking methods in an inherit
Date: Sun, 07 Sep 2003 17:03:00 +0900	[thread overview]
Message-ID: <20030907170300B.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <1062887193.3773.2363.camel@ffh.ro>

From: Ryan R Newton <newton@MIT.EDU>

> I've developed a liking for using multiple inheritacnce heavily as
> follows:
> 
> When I'm working on a library (say, an evolutionary computation library,
> or a distributed computing library), I'm real crazy about making
> composable "plug-and-play" units of functionality rather than a
> monolithic class hierarchy.  That is, I like to make a base class along
> with small virtual "layer" classes.  I combine different features by
> defining a new class which inherits from the base class and a subset of
> the layer classes.
> 
> Is there a name for this sort of pattern?  Is it a horrible idea for
> some reason?

It looks like what most people call a mixin.
Or is it different?

> Anyway, the point of this post is:  When inheriting the same method from
> two sources, I quite reasonably get this message:
> 
> "Warning: the following methods are overriden by the inherited class:"
> 
> What's the best way to get rid of it?  (Without turning off all
> warnings.)

If you just mean, turn off only this warning, this is easy

   ocamlc -w m

Clearly what you are doing is legal and reasonable, but I see no way
to avoid the warning for public methods without disabling it.

For private methods, you can hide them when inheriting, but then you
are changing the semantics (the methods will not be merged)

  class c = object
    inherit (a : object method f : int end)
    inherit b
    ...
  end
is legal if g is private in a.

The impossibility to hide public methods is fundamental to the ocaml
type system. So "inherit g without a" is impossible.

A possibility would be to disable the warning when a virtual method is
declared after inheritance.

>    class c =
>    object
>      inherit a
       method virtual g : int
>      inherit b  
>      method h = 99
>    end

This seems reasonable to have no warning in this case, the intention
being explicit enough.
Of course, if there is no definition of g in b, the definition from a
would be kept (we don't change the semantics, just the warning).

Would this avoid your problem?
Other solutions would imply new syntax, for something that is no more
than a warning.

      Jacques Garrigue

-------------------
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:[~2003-09-07  8:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-06 22:26 Ryan R Newton
2003-09-07  8:03 ` Jacques Garrigue [this message]
     [not found]   ` <1063148703.27949.43.camel@moremischief>
2003-09-10  1:06     ` 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=20030907170300B.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=newton@MIT.EDU \
    /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