<?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/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?"
  prev="2002/07/97e016810f98dca181ee792851b7e4c6"
  next="2002/07/041a364c6a3fa76a72e798b3892d9d10"
  prev-in-thread="2002/07/b0c7298c9c0bead77bcf8ed319d71bf4"
  next-in-thread="2002/07/f50104a209a6f53189e0a4d2eb220060"
  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>
From: Brian Smith &lt;brian-l-smith@uiowa.edu&gt;

&gt; Please consider the following:
&gt; 
&gt; # class virtual x = object method virtual foo : int    end
&gt;    class virtual y = object method virtual bar : string end
&gt;    class z =
&gt;      object
&gt;       method foo = 2
&gt;       method bar = "there"
&gt;      end;;
&gt; 
&gt; How can I assert that class "z" is supposed to be a subtype of class x 
&gt; and class y? In other words, how can I assert that (some_z : z :&gt; x) and 
&gt; (some_z : z :&gt; y) will always be valid?

You have many ways to force (self : #x) and (self : #y).

class z = object ((self : #x) : #y)
  method foo = 2
  method bar = "there"
end
class z = object (self : 'a)
  constraint 'a = #x
  constraint 'a = #y
  method foo = 2
  method bar = "there"
end
class z = object
  inherit x
  inherit y
  method foo = 2
  method bar = "there"
end

The last one uses the fact x and y are virtual classes, rather than
class types.

Note that none of these guarantee a subtyping relation, only a
matching one. Fortunately, as long as the type of self does not appear
in a contravariant position in x or y, this relation is included in
subtyping.

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

</contents>

</message>

