Anonymous classes

From: William Chesters (williamc@dai.ed.ac.uk)
Date: Thu Feb 18 1999 - 20:12:55 MET


Date: Thu, 18 Feb 1999 19:12:55 GMT
Message-Id: <199902181912.TAA09359@toy.william.bogus>
From: William Chesters <williamc@dai.ed.ac.uk>
To: caml-list@inria.fr
Subject: Anonymous classes

   Could we have anonymous classes, as a natural counterpart to
anonymous functions?

        let x =
          object
            method foo = 17
          end
        in
        ...

They would sometimes be useful for specifying the little bits of `glue'
one needs to interface a library routine with one's current problem.

   On the other hand maybe this kind of sugar isn't strictly
necessary, since I found this pretty easy to add with camlp4 :-),
using a dummy local module.

        expr: LEVEL "simple"
          [ [ "object"; cspo = OPT class_self_patt;
                        cf = class_structure; "end" ->
                <:expr< let module Dummy__ =
                          struct
                            class c () = object $cspo$ $list:cf$ end ;
                          end
                         in
                         new Dummy__.c () >> ] ] ;

(except that the definitions of class_structure and class_self_patt
need to be copied from pa_o.ml)



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:20 MET