From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?)
Date: Wed, 17 Jul 2002 11:26:38 +0200 [thread overview]
Message-ID: <20020717112638.K7018@verdot.inria.fr> (raw)
In-Reply-To: <3D341795.5010301@baretta.com>; from alex@baretta.com on Tue, Jul 16, 2002 at 02:54:45PM +0200
Hi,
On Tue, Jul 16, 2002 at 02:54:45PM +0200, Alessandro Baretta wrote:
> Great! Don't you think this would be a cool addition to the
> language? I like it, at least.
I cannot judge if it is a good idea or not: I never program with
objects and I don't know what is useful or not. I just answer the
syntactic point of view. For semantics, please go to the counter
"Semantics".
-----
For your change:
class a =
object
method m = <some stuff>
end
into:
class var_b =
object
inherit a as super_a through b as super_b
method m = super_a # m
end
You can do it with this file:
------------------------------------------------ foo.ml
#load "pa_extend.cmo";;
#load "q_MLast.cmo";;
open Pcaml
EXTEND
GLOBAL: class_str_item;
class_str_item:
[ [ "method"; l = LIDENT; fb = fun_binding ->
let class_a = "__class_a__" ^ l in
<:class_str_item<
declare
method private $lid:class_a$ = $fb$;
method m = self # $lid:class_a$;
end >> ] ]
;
fun_binding:
[ RIGHTA
[ p = patt LEVEL "simple"; e = SELF -> <:expr< fun $p$ -> $e$ >>
| "="; e = expr -> <:expr< $e$ >>
| ":"; t = ctyp; "="; e = expr -> <:expr< ($e$ : $t$) >> ] ]
;
END
------------------------------------------------
Compile it with:
ocamlc -pp camlp4o -I +camlp4 -c foo.ml
Then you can compile your example "bar.ml" with the command:
ocamlc -pp "camlp4o ./foo.cmo" bar.ml
You can also see what the syntax extension does with the command:
camlp4o ./foo.cmo pr_o.cmo bar.ml
-----
For the case:
class var_b =
object
inherit a as super_a through b as super_b
method m = super_a # m
end
into:
class var_b =
object
inherit b as super_b
method m = __class_a__m
end
It could be done by Camlp4 the same way but there is a small difficulty:
it is not really "syntactic sugar" since it supposes, when reaching
the item "method m = super_a # m" that you know that "super_a" has
been previously defined as "inherit a as super_a through b as
super_b".
This is mainly "semantics". I mean that the parser should record
the information that an "inherit" statement has been defined.
It is possible, of course, and I can give you the code which
does that, but is it not supposed to be Camlp4 work, if you want
to be "pure". The code risks to be a "hack". You have probably to
use references to record this information to be possibly used
afterwards.
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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
next prev parent reply other threads:[~2002-07-17 9:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-15 23:13 [Caml-list] Recovering masked methods Alessandro Baretta
2002-07-16 1:15 ` Jacques Garrigue
2002-07-16 9:28 ` Alessandro Baretta
2002-07-16 9:48 ` Laurent Vibert
2002-07-16 10:08 ` Johan Baltié
2002-07-16 10:10 ` Alessandro Baretta
2002-07-16 9:59 ` Johan Baltié
2002-07-16 11:08 ` [Caml-list] Recovering masked methods (with CamlP4?) Alessandro Baretta
2002-07-16 11:32 ` Johan Baltié
2002-07-16 12:52 ` Alessandro Baretta
2002-07-16 12:26 ` Daniel de Rauglaudre
2002-07-16 12:54 ` Alessandro Baretta
2002-07-17 9:26 ` Daniel de Rauglaudre [this message]
2002-07-16 13:32 ` John Prevost
2002-07-16 13:35 ` John Prevost
2002-07-16 14:06 ` Alessandro Baretta
2002-07-16 14:15 ` Johan Baltié
2002-07-16 14:29 ` Alessandro Baretta
2002-11-11 9:20 ` Eray Ozkural
2002-07-16 10:45 ` [Caml-list] Recovering masked methods John Prevost
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=20020717112638.K7018@verdot.inria.fr \
--to=daniel.de_rauglaudre@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