Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "François Pottier" <francois.pottier@inria.fr>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] How to indicate that I am overriding an inherited virtual method?
Date: Fri, 13 Jan 2017 10:09:06 +0100	[thread overview]
Message-ID: <99968acc-c9f1-273f-d983-4a286a2e8068@inria.fr> (raw)


Dear OCaml users,

Is there an OCaml equivalent of Java's @Override keyword, which allows
indicating that a method definition is intended to override an inherited
(virtual or concrete) method?

As far as I can see, in OCaml, the "method!" form works for inherited 
concrete
methods:

   class base = object
     method foo: string = "uh?"
   end

   class child = object
     inherit base
     method! foo = "ha!"
       (* OK *)
   end

but does not work for inherited virtual methods:

   class virtual base = object
     method virtual foo: string
   end

   class child = object
     inherit base
     method! foo = "ha!"
       (* Error: The method `foo' has no previous definition *)
   end

Is this intentional?

This is too bad. I seem to be forced to use "method" instead of "method!".
Therefore, I cannot indicate my intent, and if I mistype the name "foo" in
the definition of the child class, the compiler cannot catch this mistake.
(Well, in this case, it can, as the child class is not declared virtual.)

--
François Pottier
francois.pottier@inria.fr
http://gallium.inria.fr/~fpottier/

             reply	other threads:[~2017-01-13  9:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13  9:09 François Pottier [this message]
     [not found] ` <CADDcBWXDbGyntNnv22Z4hv5K98OXu21mxS2d8Ju7k8ygqAmaQQ@mail.gmail.com>
2017-01-13 11:04   ` François Pottier

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=99968acc-c9f1-273f-d983-4a286a2e8068@inria.fr \
    --to=francois.pottier@inria.fr \
    --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