Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pierre Weis <Pierre.Weis@inria.fr>
To: skaller@maxtal.com.au (skaller)
Cc: caml-list@inria.fr
Subject: Re: Can someone explain?
Date: Mon, 4 Oct 1999 10:23:49 +0200 (MET DST)	[thread overview]
Message-ID: <199910040823.KAA21438@pauillac.inria.fr> (raw)
In-Reply-To: <37F10F65.47A4212C@maxtal.com.au> from "skaller" at Sep 29, 99 04:56:37 am

> Is there a way to access a value of a class instance?
> If so, what is the syntax? If not, what is the purpose
> of allowing 'val' bindings in class declarations in module
> signatures?

The only way to access a value of a class instance is via method
invocation: you have to define a method that returns the value.

> Similarly, what is the purpose of allowing 'virtual'
> methods in class types and class declarations in
> module signatures?

Virtual methods are methods that are declared but not implemented:
sub-classes must define them.

> I have a doubly linked list class, and concatenating 
> two lists takes 100 times longer in ocaml using my
> code than pythons list concatenation function,
> which is written in C.

Wao! I would like to be able to run your benchmark, since I will be
glad to try to use the Python's way of handling lists to speed up the
Caml list package by a factor of 100! We worked hard on this point,
and Caml lists (and more generally similar data structure
manipulations) are supposed to be among the fastest known
implementations available. So, could you please send a complete
reproducible benchmark ?

> My code isn't optimal (given the particular data structure
> I've chosen) because the concat function cannot
> get at values of the class. Excerpt given below.
> Any advice appreciated. (A high speed mutable list
> in the standard library would be even better :-)

As you suggested, we may add extra list manipulation modules in the
standard library, such as mutable lists or doubly linked
lists. Mutable lists are easy to implement and there is no doubt that
many Caml programmers have already written such kind of packages and
can contribute.

About your own program, I cannot comment on efficiency, since I do not
catch the general idea of the design: I am a bit surprised by the
melting of object oriented features and regular algebraic data type
manipulation to implement lists. Could you please explain a bit the
logic of your code (in particular the only comment
(* STL style mutators *) is a kind of puzzle for me) ?

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/

> module DoublyLinkedList : BiDirectional =
>   struct (* doubly linked list type *)
>     type 't d_node = 
>       {
>         mutable nxt: 't iterator; 
>         mutable prv: 't iterator;
>         mutable data: 't
>       }
> 
>     and 't iterator = 
>       Empty 
>       | Node of 't d_node
> 
>     let next x = match x with Empty -> Empty | Node n -> n.nxt
>     let deref x = match x with Empty -> None | Node n -> Some n.data
> 
>     class ['t] dlist = 
>       object(self)
>         val mutable first': 't iterator = Empty
>         val mutable last':  't iterator = Empty
>         val mutable size: int = 0
> 
>         method private init node = 
>           last' <- node; 
>           first' <- node;
>           size <- 1
> 
>         method length = size
> 
>         (* STL style mutators *)
>         method push_back (data':'t): unit = 
>           match last' with
>           | Empty -> self#init (Node {nxt=Empty; prv=Empty; data=data'})
>           | Node fin -> 
>             let tmp = Node {nxt=Empty; prv=last'; data=data'}  in 
>               fin.nxt <- tmp;
>               last' <- tmp;
>               size <- size + 1
> 
>         method first = first'
>      end
> 
>     let concat (x:'a dlist) (y:'a dlist) :'a dlist = 
>       let z = new dlist in
>       let i = ref x#first in
>       while deref !i <> None do 
>         match deref !i with 
>         | Some v -> z#push_back v; i := next !i 
>         | None -> assert false
>       done;
>       let j = ref y#first in
>       while deref !j <> None do 
>         match deref !j with
>         | Some v -> z#push_back v; j := next !j 
>         | None -> assert false
>       done;
>       z
> end
> 
> -- 
> John Skaller, mailto:skaller@maxtal.com.au
> 1/10 Toxteth Rd Glebe NSW 2037 Australia
> homepage: http://www.maxtal.com.au/~skaller
> downloads: http://www.triode.net.au/~skaller





  reply	other threads:[~1999-10-04  8:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-09 16:34 strange behavior of the object type-checker Pierre Boulet
1999-09-09 19:43 ` Jerome Vouillon
1999-09-28 18:56   ` Can someone explain? skaller
1999-10-04  8:23     ` Pierre Weis [this message]
1999-10-04 22:57       ` skaller
1999-10-05  9:43         ` Jerome Vouillon
1999-10-05 19:35         ` Gerd Stolpmann
1999-10-06  9:42           ` skaller
1999-10-08  0:17           ` Problem of coercion in recursive class definitions Peter Schrammel
1999-10-05 21:42         ` Can someone explain? Lyn A Headley
1999-10-06 10:17           ` skaller
1999-10-13 19:16 Juergen Pfitzenmaier

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=199910040823.KAA21438@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=skaller@maxtal.com.au \
    /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