caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: briand@aracnet.com
To: Matt Gushee <mgushee@havenrock.com>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] examples of heterogenous collections (containers ?)
Date: Tue, 30 Mar 2004 22:45:10 -0800	[thread overview]
Message-ID: <16490.26870.331855.463270@soggy.deldotd.com> (raw)
In-Reply-To: <20040331054113.GC19538@swordfish>

>>>>> "Matt" == Matt Gushee <mgushee@havenrock.com> writes:

  Matt> This will work if all the classes have identical signatures. Of course,
  Matt> that's not the case for most non-trivial examples.

The classes have identical signatures, i.e. all have exactly the same
methods and variables ??


  Matt> Probably not. First of all, you will need to cast the objects at the
  Matt> point where you put them into a list together ... thus, at the point
  Matt> where you do the method call, the cast has already been done. Second,
  Matt> you don't necessarily want to cast them to the base class.

Well that makes sense, if I can figure out the part about all the
classes havin g the same signature.

  Matt> As some people never tire of pointing out ;-), inheritance is
  Matt> not subtyping. Actually, I haven't myself figured out all the
  Matt> implications of that statement, nor learned the theoretical

Yes, I've been seeing that, and amazingly it's actually starting to
sink in.  There are some notes from the ocaml page which discuss this
relatively well : Didier Remy's APPSEM course notes on Objective Caml.

  Matt> justification for it--but at any rate, in OCaml class types
  Matt> are completely independent of inheritance
  Matt> relationships. That's a good thing because it means you can
  Matt> define a class type and arbitrarily apply it to any class that
  Matt> provides *at least* the methods specified in the type
  Matt> signature, regardless of inheritance. E.g.:

  Matt>   class type x =
  Matt>     object
  Matt>       method a : unit
  Matt>       method b : int -> bool
  Matt>     end

  Matt> ... and so on.

??? So it's example time :

class virtual base =
  ...
end

class A1 = object(self)
inherit base
method x1 = ...
method x2 = ...
end

class A2 = object(self)
inherit base
method x1 = ...
method x2 = ...
method x3 = ...
end

So I should be able to do :

let a = new A1 in
let b = new A2 in
  (a :> base) :: (b :> base) :: []
;;


right ?  now my list has type "base list".

So I immediately see the problem here.

My iter code could try to invoke method x3 on the A1 object in the
list as I'm iterating through. oops.

So it seems to me that I need a "stronger" method to enforce safety,
perhaps implementing x1 as a virtual method in base ?

Brian

-------------------
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-03-31  6:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-31  4:55 briand
2004-03-31  5:41 ` Matt Gushee
2004-03-31  6:45   ` briand [this message]
2004-03-31  9:04     ` skaller
2004-04-01  4:00       ` briand
2004-04-01  5:38         ` Issac Trotts
2004-04-01  7:20         ` skaller
2004-03-31  7:28   ` Martin Jambon

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=16490.26870.331855.463270@soggy.deldotd.com \
    --to=briand@aracnet.com \
    --cc=caml-list@pauillac.inria.fr \
    --cc=mgushee@havenrock.com \
    /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).