<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/b0c7298c9c0bead77bcf8ed319d71bf4"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-12T05:33:55"
  subject="[Caml-list] Syntax for multiple subtyping constraints?"
  prev="2002/07/895c189fc1924ba0778af55006e0dbc8"
  next="2002/07/60566155d8619b00da34b196b30a728c"
  next-in-thread="2002/07/1b200a8bc26f7591dc09b585bcb5433d"
  prev-thread="2002/07/1fdaa5e902b0c73415d567249ed998ad"
  next-thread="2002/07/55221a6e50e64420b97504ccc84af871"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Syntax for multiple subtyping constraints?">
<msg 
  url="2002/07/b0c7298c9c0bead77bcf8ed319d71bf4"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-12T05:33:55"
  subject="[Caml-list] Syntax for multiple subtyping constraints?">
<msg 
  url="2002/07/1b200a8bc26f7591dc09b585bcb5433d"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-12T08:54:30"
  subject="Re: [Caml-list] Syntax for multiple subtyping constraints?">
</msg>
<msg 
  url="2002/07/f50104a209a6f53189e0a4d2eb220060"
  from="John Max Skaller &lt;skaller@o...&gt;"
  author="John Max Skaller"
  date="2002-07-12T13:21:26"
  subject="Re: [Caml-list] Syntax for multiple subtyping constraints?">
</msg>
</msg>
</thread>

<contents>
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 :&gt; x) and 
(some_z : z :&gt; 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

</contents>

</message>

