caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* additions to standard library?
@ 2000-03-07 15:24 Markus Mottl
  2000-03-08 19:03 ` Jean-Christophe Filliatre
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Markus Mottl @ 2000-03-07 15:24 UTC (permalink / raw)
  To: OCAML

Hello,

it sometimes happens that I need functions on abstract data types in the
standard library which are not available there, but could be considered as
"usual" operations on such data. Also some other very commonly useful
functions could be added.

I was just wondering which way would be best to propose additions to the
standard libraries - I have modified a few standard modules, which now
contain additional functionality that might be useful for others, too.  Is
it a good idea to send patches against the standard library in the hope
that they might be integrated?

Some specific examples include, e.g.:

  * Char: functions like is_upper, is_lower, is_alpha, is_...

  * Set: functions like for_all, exists, filter (find_all), partition.

         These functions are in "List", too, but actually fit perfectly
         to sets.

  * Stack: with function top

           Currently, the only way to use "Stack" in such a way is to
           pop an element and push it again...

  * String: the functions explode and implode for conversions of char
            lists to strings and vice versa.

            Especially useful for teaching, because it allows students to
            use a functional style of programming when implementing string
            algorithms.

There are some other additions, too, which I haven't yet fully integrated
into standard library modules.

Other people surely also have proposals for further additions to the
libraries. I can imagine that the OCaml-development team does not have the
time to deal with all such suggestions.

What do you think about the idea to make use of the "usercontrib"
CVS-repository at INRIA for such purposes? We could open a "stable" and
"development" branch for standard libraries (and "otherlibs") there, where
people could place and "peer review" their contributions. From time to
time, the OCaml-team can peek at the additions and take what they consider
useful.

This approach might be appealing to both sides:

  * the OCaml-team can decide when to integrate what and won't get a bad
    conscience by having to "bin" user suggestions.  Additionally, some
    "boring" development work can be delegated to the user community (I
    know that developing compilers is more interesting than writing
    standard libraries... ;-)

  * the user community finally has a means to express their wishes in a
    more direct way - which might increase the probability that suggestions
    really get considered.

What do the developers and other users think of this idea?

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: additions to standard library?
@ 2000-03-10 17:55 Manuel Fahndrich
  0 siblings, 0 replies; 15+ messages in thread
From: Manuel Fahndrich @ 2000-03-10 17:55 UTC (permalink / raw)
  To: 'Markus Mottl'; +Cc: caml-list


The issue you are raising is a good one. SML/NJ can handle some of it,
because the semantics of "open" are different there. Once can actually say:

	module Foo = struct
        open B
      end

and obtain a copy of B within Foo.

This might even work to extend functors as in:

	functor Foo(Arg : A) =
        struct
           module B = Bar(A)
           open B
           let extensions = ...
        end


However, this interpretation of "open" has impacts on compilation
dependencies, in particular scoping analysis (See e.g.  "Dependency analysis
for Standard ML; Matthias Blume; ACM Trans. Program. Lang. Syst. 21, 4 (Jul.
1999), Pages 790 - 812").

-Manuel



-----Original Message-----
From: Markus Mottl [mailto:mottl@miss.wu-wien.ac.at]
Sent: Friday, March 10, 2000 12:04 AM
To: caml-redistribution@pauillac.inria.fr
Cc: caml-list@inria.fr
Subject: Re: additions to standard library?


> But  when  using functorial  interfaces  like  Set.Make,  you have  to
> redefine these  functions for each  application of the  functor. Thus,
> you  really need these  functions to  be defined  in the  functor i.e.
> together with the datatype (and, by the way, you can then define these
> functions a bit more efficiently---without using exceptions).

Exactly - this raises another question which has been bothering me from
time to time when using the module system:

How can you extend the functionality of a module without having to "copy"
the definitions of the underlying module "by hand"? In a case which I found
particularly ugly (in the "res"-library), I had to "copy" nearly 100 lines
as in:

  module Foo = struct
    module B = ...
    type t = B.t
    ...
    let iter = B.iter
    let iteri = B.iteri
    let map = B.map
    let mapi = B.mapi
    ...
  end

Everytime the other module gets extended, I have to add code by hand here,
too, to make it available. I do not see any simple workaround for this.
Extending standard libraries with needed functionality would be much easier
if there were a convenient way to get around the problem above.

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: additions to standard library?
@ 2000-03-14 17:24 Don Syme
  2000-03-21 21:08 ` John Max Skaller
  0 siblings, 1 reply; 15+ messages in thread
From: Don Syme @ 2000-03-14 17:24 UTC (permalink / raw)
  To: 'caml-list@inria.fr'

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3723 bytes --]


I've often wondered why languages don't support "extensions" to library
namespaces (and perhaps even to functors).  e.g. one could define 

let String.explode s = ....
let String.implode s = ...
let myfun = ...

If you like you can consider this as a shorthand for the longwinded
declaration of a module and the rebinding of member names.  Since all the
typing mechanisms are "monotonic" w.r.t. adding new members to a module
(i.e. if a module matched a signature before it will continue to match after
an addition like the above) then this should make sense theoretically.   The
implementation can probably just whack in another element to the dictionary
structure that represents a module.  

The "signature" of a seperately compilation unit would probably have to
declare how the unit extends existing structures, functors and signatures,
e.g. the .mli for the above code might be: 

val String.explode : string -> char list
val String.implode : char list -> string
val myfun : int -> int

I put "signature" in quotes because the extensions are not part of signature
of the module defined by the unit itself (i.e. the rule "each compilation
unit introduces one new top level module" would be relaxed.

You then probably need a distinction between "open" and "load", i.e. open a
top level module namespace and load a compilation unit, and you probably
need to explicitly load any compilation units that define extensions (rather
than relying on the default behaviour of OCaml where a compilation unit is
"loaded" by virtue of using a module access, e.g. Myfile.myfun).  For
example:

(A) open Myfile  (* myfun now in scope *)

(B) load Myfile  (* String.explode, String.implode, Myfun.myfun now in
scope. *)
    open Myfile  (* myfile becomes available *)

(B) Myfile.myfile (* OK - but String.explode not available without an *)
                  (* explicit load *)

I think that with that distinction in place dependency analysis would be OK.
More ambitiously, perhaps one could even extend functors coherently in this
way, i.e. 

let Set.Make(Ord: OrderedType).set_exists = ...

Realistically you probably need a way of accessing the existing elements
generated by the application, which we could do by reusing my favourite
keyword "as".... e.g

let (Set.Make(Ord: OrderedType) as M).set_exists = ...
    try M.fold (fun x _ -> if p x then failwith "t") s (); false
    with Failure "t" -> true

This is all quite similar to the mechanisms I used for the module mechanism
in my theorem prover "Declare", which didn't have functors as such, but even
the basic mechanisms certainly did make the abstract algebra examples I did
look quite nice.

Don

P.S. I don't know if you could also add types to modules in this way?



-----Original Message-----
From: Jerome Vouillon [mailto:Jerome.Vouillon@inria.fr]
Sent: 13 March 2000 09:26
To: caml-redistribution@pauillac.inria.fr
Subject: Re: additions to standard library?


On Tue, Mar 07, 2000 at 04:24:00PM +0100, Markus Mottl wrote:
> What do you think about the idea to make use of the "usercontrib"
> CVS-repository at INRIA for such purposes? We could open a "stable" and
> "development" branch for standard libraries (and "otherlibs") there, where
> people could place and "peer review" their contributions. From time to
> time, the OCaml-team can peek at the additions and take what they consider
> useful.

I see two dangers:
- this could result in an over-featured library;
- the "regular" and the "extended" library may diverge.
On the other hand, I don't think it would be a bad thing if more
people contributed to the development of O'Caml.

Anyway, you can always set up a repository on Sourceforge or any
similar site and see what happens. :-)

-- Jérôme



^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: additions to standard library?
@ 2000-03-21 21:43 Don Syme
  0 siblings, 0 replies; 15+ messages in thread
From: Don Syme @ 2000-03-21 21:43 UTC (permalink / raw)
  To: 'John Max Skaller'; +Cc: 'caml-list@inria.fr'

> > I've often wondered why languages don't support "extensions" to library
> > namespaces (and perhaps even to functors).  e.g. one could define
> > 
> > let String.explode s = ....
> > let String.implode s = ...
> > let myfun = ...
> 
> The reason is that it is hard to localise these changes.
> It isn't acceptable to extend the actual module, since two clients
> could provide conflicting "extensions". This would break the
> Open/Closed principle [Meyer, OOSC]

With regard to conflicts, I don't see that taking a strict approach is
particularly wonderful.  Scoping and locality are, of course, important, and
of course you still have to be able to know exactly the signatures you are
compiling against (i.e. the sum of all the extensions you've imported).
Conflicts can be detected whenever you try to combine extensions (compile
time or link time) - of course conflicts can occur, but that doesn't mean
the facility is not very useful when they do not.  Effectively the same
problem occurs when you do this "module List2 = struct include List ... end"
nonsense, with the horrible proliferation of modules and extensions that
result, and nightmarish management of extensions.  Even in this setting
there's no way around the potential for conflicts, but, if you assume they
aren't going to occur (e.g. because of some agreed project management of a
namespace), then what's the best way forward?  I think optimistic is better
than pessimistic: make the most pleasant system to use, assuming conflicts
won't occur, but if they do give errors at compile time.

[ I also think you could implement it so that only conflicts at compile time
(rather than link time) were significant, by qualifying names in generated
code according to their compilation units. This gives you quite a high
degree of locality, and even if conflicts occur between two extensions
you're using, you can choose, by restricting one signature or another
appropriately, which parts of which extension you want to make use of.  Or
something like that.  ]

With regard to open/closed, in ML, the signature mechanism provides the way
to close structures and restrict access.  Thus I don't think allowing
clients to extend the underlying _structures_ contravenes this.  I wouldn't
want to be able to extend _signatures_ that other clients rely upon, unless
they see and explicitly make use of my extension.  And the extender would
not receive any special rights to access aspects of the structure hidden
from me.

Thus, for example, you could still implement an abstract data type and
restrict access globally via a signature.  No one could mess with your data
type by extending your module, because no one has the privileges necessay to
access the underlying representation.  However they could augment your
module with their own stuff, which could be very, very useful, as the Set
functor example indicates.

In an OO setting, particularly with overriding, the question may be
different, but that's not quite what we're talking about here.  However,
even Java binary compatibility, for example, specifies ways in which the
classes you run against may be "richer" than the ones you compiled against.
The question is just one of who gets to extend, what rights they have, and
how this maps onto the namespace facility of a language.

Cheers!
Don

-----Original Message-----
From: John Max Skaller [mailto:skaller@maxtal.com.au]
Sent: 21 March 2000 21:08
To: Don Syme
Cc: 'caml-list@inria.fr'
Subject: Re: additions to standard library?


Don Syme wrote:
> 
> I've often wondered why languages don't support "extensions" to library
> namespaces (and perhaps even to functors).  e.g. one could define
> 
> let String.explode s = ....
> let String.implode s = ...
> let myfun = ...

The reason is that it is hard to localise these changes.
It isn't acceptable to extend the actual module, since two clients
could provide conflicting "extensions". This would break the
Open/Closed principle [Meyer, OOSC]

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2000-03-22 16:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-07 15:24 additions to standard library? Markus Mottl
2000-03-08 19:03 ` Jean-Christophe Filliatre
2000-03-08 22:29   ` Markus Mottl
2000-03-10 10:51     ` Christian RINDERKNECHT
2000-03-09 13:18 ` Thorsten Ohl
2000-03-10 10:04   ` Francisco Valverde Albacete
2000-03-10 20:33     ` Markus Mottl
2000-03-14 23:15       ` Max Skaller
2000-03-11 18:49     ` Brian Rogoff
2000-03-12  1:54 ` Jerome Vouillon
     [not found]   ` <200003120239.DAA18581@miss.wu-wien.ac.at>
2000-03-14 17:53     ` Pierre Weis
2000-03-10 17:55 Manuel Fahndrich
2000-03-14 17:24 Don Syme
2000-03-21 21:08 ` John Max Skaller
2000-03-21 21:43 Don Syme

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).