caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Patrick M Doane <patrick@watson.org>
To: Brian Rogoff <bpr@best.com>
Cc: John Max Skaller <skaller@ozemail.com.au>,
	Jun Furuse <Jun.Furuse@inria.fr>,
	caml-list@inria.fr
Subject: Re: "Re: [Caml-list] A G'Caml question" + additional info
Date: Sun, 1 Jul 2001 01:32:56 -0400 (EDT)	[thread overview]
Message-ID: <Pine.BSF.3.96.1010701002926.69456B-100000@fledge.watson.org> (raw)
In-Reply-To: <Pine.BSF.4.21.0106301328440.2975-100000@shell5.ba.best.com>

On Sat, 30 Jun 2001, Brian Rogoff wrote:

> On Sat, 30 Jun 2001, Patrick M Doane wrote:
> > On Sat, 30 Jun 2001, John Max Skaller wrote:
> > > 	G'caml makes it easier to write readable algorithms,
> > > and to do 'cut and paste' genericity. But it can't do what
> > > you can do in C++. 
> > I agree.  Although I'm not advocating that it do everything you can do in
> > C++.
> 
> Less talk, more coding examples please.

Here's a simple example motivating my thoughts in this discussion:

generic get = case
  | string -> int -> char => String.get

let print_first x = get x 0

generic get = case
  | include get
  | $a array -> int -> $a => Array.get
;;
print_first [|0|]

As far as I can tell, there are no current plans for this kind of code
to work with G'caml.

> GCaml polymorphism is remarkably
> easy to use. A while ago, when there was some discussion of overloading
> on the list, Pierre Weis mentioned that he'd like a style of overloading
> that would allow us to overload array access, string access, and hashtbl
> access. How easy is that? Well, it writes itself from that sentence
> 
> generic get = case
>   | string -> int -> char  => String.get
>   | $a array -> int -> $a  => Array.get
>   | $a list -> int -> $a => List.nth
>   | ($a,$b) Hashtbl.t -> $a -> $b => Hashtbl.find 
>   | ($a -> $b) -> $a -> $b => fun f -> f;;

This part works great - we get clear and powerful overloading. I really
like it!

> This extensional polymorphism is beautiful, as well as practical. One of
> the nice things about the STL is the way that it allows you to write the
> algorithms independently of the containers, using the iterator interfaces. 
> You can write functions over generics like "get" to achieve the same
> effect in GCaml. 

The algorithms and containers can't be independent though because either:

  1) All containers (generic values) must be declared before any
algorithms (derived generics) which use them are declared. 

  2) Derived generics must include the generic values as parameters.

The first solution makes it difficult for users to extend a system.  If I
redefine a generic value like get, then existing code cannot make use of
it unless I 'cut and paste' to achieve genericity.

The second solution is similar to what we have in O'caml today, although
with G'Caml I can refer to things by a common name and get some cool
functions that were not expressible before. 

> > > > The proposed 'include' feature makes it much easier to
> > > > extend generic values, but doesn't help with derived generics. 
> 
> How doesn't it help?

The include feature, if I understand the proposition correctly, only
applies to generic values and would not effect any derived generics that
have been defined.  So I can't easily extend the definition of 'get' and
have existing code make use of those improvements.  Here are some possible
ideas: 

 1) Add a feature like 'include' which re-evaluates the definition of a
derived generic in the current context.  This simplifies the 'cut and
paste' approach by not specifying the code redundantly.

 2) Modify the semantics of derived generics such that the use of a
generic value depends on a link-time (or run-time) analysis.  It was
pointed out that this could be difficult to understand, but the OO system
already has a similar confusion.

 3) Delegate this issue to the use of objects or functors.

> > > 	Objects can help, but really that isn't the answer.
> > > The answer is more like: what can we do to make C++ like
> > > generics properly parametric?
> > > 
> > > 	It is possible to make STL like algorithms in Ocaml now.
> > > The problem is that you have to pass in a LOT of data, such as
> > > functions to deref and increment the iterator.
> > 
> > I think that one can implement much of the STL algorithms in the Caml
> > object system (avoiding the need to pass lots of data). 
> 
> While I think the STL is a fine design for a language like C++, I'm not
> sure that STL emulation is high on my list of criteria for an OCaml 
> overloading extension. 

Yes, the STL has little support for functional programming, and has other
aspects which are messy.  Attempting to implement something close to STL
in G'Caml is still a useful exercise though.  We can get a better sense
for the differences between the two langauges.

The point I wanted to make was that the object system can express many
concepts of the C++ template system. I can't think of anything that
wouldn't be expressible when G'caml is integrated with O'caml objects. 

> Once that include feature is in *and* it is integrated with the rest of
> the type system (modules and signatures, classes, polymorphic variants,
> etc.) we'll have an enormous amount of power. 

I think we both want a system which allows for data structures and
algorithms to be independent.  So far, I can't see how all the pieces will
fit together though.

Patrick


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-07-01  5:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3B3D503C.E91DDE34@ozemail.com.au>
2001-06-30 16:01 ` Patrick M Doane
2001-06-30 20:59   ` Brian Rogoff
2001-07-01  5:32     ` Patrick M Doane [this message]
2001-07-02 15:55       ` Brian Rogoff
2001-07-10 18:08         ` Patrick M Doane
2001-07-16 18:24 John R Harrison
  -- strict thread matches above, loose matches on Subject: below --
2001-07-11 14:30 Krishnaswami, Neel
2001-07-11 16:22 ` Brian Rogoff
2001-07-11 16:35   ` Bruce Hoult
2001-07-11 19:12     ` Markus Mottl
2001-07-12  3:15   ` Patrick M Doane
2001-07-10 18:21 Krishnaswami, Neel
2001-07-11  6:09 ` Sven
     [not found] <3B3BB6EC.3DEB6CBF@ozemail.com.au>
2001-06-29  4:18 ` Patrick M Doane
2001-06-20  3:16 [Caml-list] A G'Caml question Brian Rogoff
2001-06-25 17:11 ` "Re: [Caml-list] A G'Caml question" + additional info Jun Furuse
2001-06-28  2:21   ` Patrick M Doane
2001-06-28  4:40     ` Brian Rogoff

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=Pine.BSF.3.96.1010701002926.69456B-100000@fledge.watson.org \
    --to=patrick@watson.org \
    --cc=Jun.Furuse@inria.fr \
    --cc=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=skaller@ozemail.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;
as well as URLs for NNTP newsgroup(s).