caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Smith <brian-l-smith@uiowa.edu>
To: OCaml Mailing list <caml-list@inria.fr>
Subject: [Caml-list] Syntax for multiple subtyping constraints?
Date: Fri, 12 Jul 2002 00:33:51 -0500	[thread overview]
Message-ID: <3D2E6A3F.70001@uiowa.edu> (raw)

Hello everbody,

Please consider the following:

# class virtual x = object method virtual foo : int    end
   class virtual y = object method virtual bar : string end
   class z =
     object
      method foo = 2
      method bar = "there"
     end;;

How can I assert that class "z" is supposed to be a subtype of class x 
and class y? In other words, how can I assert that (some_z : z :> x) and 
(some_z : z :> y) will always be valid? I tried:

# class z =
     object (self : #x, self : #y)
      method foo = 2
      method bar = "there"
     end;;
Characters 29-30:
     object (self : #x, self : #y)
                      ^
Syntax error

But, it only works for one supertype, e.g.:

class z =
   object (self : #x) (* or (self : #y) *)
    method foo = 2
    method bar = "there"
   end;;

I know that I could just leave it out and everything would work, but I 
want to specify that z is supposed to be a subtype of both x and y so 
that, if I screw up the definition of class z, the compiler will give me 
an error. For example, if I didn't define the method "bar" in class "z", 
I want to get the error:

   This class  type should be virtual
   The following methods are undefined : bar

Thanks,
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:[~2002-07-12  5:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-12  5:33 Brian Smith [this message]
2002-07-12  8:54 ` Jacques Garrigue
2002-07-12 13:21 ` John Max Skaller

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=3D2E6A3F.70001@uiowa.edu \
    --to=brian-l-smith@uiowa.edu \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).