From: Andrej Bauer <Andrej.Bauer@fmf.uni-lj.si>
To: Luca de Alfaro <luca@dealfaro.org>
Cc: Inria Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Why can't I call a function over a subclass?
Date: Fri, 05 Oct 2007 12:55:14 +0200 [thread overview]
Message-ID: <47061812.2020409@fmf.uni-lj.si> (raw)
In-Reply-To: <28fa90930710050048p3d6f4e8cs8e13d0fe49d296f2@mail.gmail.com>
Ocaml will compute types for you. If you want, you can also specify the
types and it will repsect that. You specified the types of r1 and r2:
> let f (r1: r) (r2: r) : bool = (r1#get_x = r2#get_x)
Even though r' is a subclass of r, a value of type r' is _not_ of type
r (if your brain thinks in Java you might find this surprising--in which
case we can talk about it):
# let a = new r' 5 ;;
val a : r' = <obj>
# (a : r);;
Characters 1-2:
(a : r);;
^
This expression has type r' but is here used with type r
Only the first object type has a method get_xx
If you let Ocaml compute types on its own, your example will work as
expected:
let f r1 r2 = (r1#get_x = r2#get_x)
Now the function of f is computed to be
val f : < get_x : 'a; .. > -> < get_x : 'a; .. > -> bool
So just let the machine worry about they types.
Andrej
prev parent reply other threads:[~2007-10-05 10:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-05 7:48 Luca de Alfaro
2007-10-05 8:01 ` [Caml-list] " Florian Hars
2007-10-05 8:08 ` Luca de Alfaro
2007-10-05 8:08 ` Fwd: " Luca de Alfaro
2007-10-05 11:08 ` Vincent Aravantinos
2007-10-05 11:47 ` Christophe Raffalli
2007-10-05 10:30 ` David Teller
2007-10-05 10:53 ` Zheng Li
2007-10-05 14:02 ` [Caml-list] " David Teller
2007-10-05 14:59 ` Luca de Alfaro
2007-10-05 15:12 ` Luca de Alfaro
[not found] ` <20071005152130.M41697@cs.unm.edu>
2007-10-05 15:49 ` Luca de Alfaro
2007-10-05 16:34 ` Edgar Friendly
2007-10-05 17:39 ` Luca de Alfaro
2007-10-05 17:49 ` Martin Jambon
[not found] ` <28fa90930710052153k2128bb63m5132455868eb2008@mail.gmail.com>
2007-10-07 22:19 ` Martin Jambon
2007-10-07 22:57 ` Classes and polymorphism (Re: [Caml-list] Re: Why can't I call a function over a subclass?) Martin Jambon
2007-10-05 19:48 ` Why can't I call a function over a subclass? Zheng Li
2007-10-06 1:49 ` [Caml-list] " Jake Donham
2007-10-09 4:18 ` Jacques Garrigue
2007-10-05 8:07 ` [Caml-list] " Pietro Abate
2007-10-05 10:55 ` Andrej Bauer [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=47061812.2020409@fmf.uni-lj.si \
--to=andrej.bauer@fmf.uni-lj.si \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@inria.fr \
--cc=luca@dealfaro.org \
/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