caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Peng Zang <peng.zang@gmail.com>
To: caml-list@yquem.inria.fr
Cc: Jacques Le Normand <rathereasy@gmail.com>
Subject: Re: [Caml-list] class constraints
Date: Fri, 27 Mar 2009 10:22:22 -0400	[thread overview]
Message-ID: <200903271022.25199.peng.zang@gmail.com> (raw)
In-Reply-To: <f74178430903270706h4be1bfa3p56913b557d5a4b95@mail.gmail.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps you mean this?

  class type foo = object('self)
    method get_parent : 'self
  end

  class type foo2 = object('self)
    constraint foo2 = #foo
    method baz : float
    method get_parent : 'self
  end


The error you get is because the first get_parent returns a foo, while the 
second returns a foo2.  While you can write a function that takes "foo or 
foo2" or really anything that is "foo-able", but you can't write a function 
that returns "foo or foo2".  When it comes to return types you have to choose 
what to return.  At least.. that's how I understand it.

Peng


On Friday 27 March 2009 10:06:03 am Jacques Le Normand wrote:
> Dear list,
> I'm having a little problem understanding constraints in objects. Consider
> the following code:
>
> class type foo =
> object
>   method get_parent : foo
> end
>
> class type foo2 =
> object
>   constraint foo2 = #foo
>   method baz : float
>   method get_parent : foo2
> end
>
> it gives me the following error:
>
> The abbreviation foo2 expands to type < baz : float; get_parent : foo2 >
> but is used with type #foo
>
> but foo2 is clearly a subtype of foo. What am I doing wrong? I'm using
> ocaml 3.10.2
> --Jacques Le Normand
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFJzOEhfIRcEFL/JewRAknhAJ46Gn8jv6azaR0aVJZtZo/GENIlOACfUOA4
lcS+swOu0JQ4ewvtvjKAFkQ=
=nt3C
-----END PGP SIGNATURE-----


      reply	other threads:[~2009-03-27 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-27 14:06 Jacques Le Normand
2009-03-27 14:22 ` Peng Zang [this message]

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=200903271022.25199.peng.zang@gmail.com \
    --to=peng.zang@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=rathereasy@gmail.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).