caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ville-Pertti Keinonen <will@exomi.com>
To: "Mattias Waldau" <mattias.waldau@abc.se>
Cc: <erayo@cs.bilkent.edu.tr>, "'Ocaml Mailing List'" <caml-list@inria.fr>
Subject: Re: [Caml-list] Efficiency of 'a list
Date: Sat, 3 May 2003 11:16:58 +0300	[thread overview]
Message-ID: <9BE14E24-7D3F-11D7-BCFA-000393863F70@exomi.com> (raw)
In-Reply-To: <03b801c31136$e122db50$0200a8c0@gateway>


> Many modern programming languages (JavaScript, Perl, PHP) have arrays
> that can take arbitrary keys as an index. This makes many people use
> them all the time, and it makes the programs resonable efficient, since
> people do not loop all the time.

They aren't arrays, you most likely mean maps aka hashes aka 
associative arrays, which are an entirely different type.

> I think more conventional languages like Java and Ocaml could learn 
> from
> this and introduce more advanced data structures as primitives, for
> example replace lists by sets, and let arrays take arbitrary data types

One big difference here is that the languages providing high-level 
primitive datatypes are much higher level languages, and they are 
dynamically typed.  They need higher level primitive types because you 
can't define your own types efficiently enough.

Java and OCaml are statically typed, which has significant advantages 
in terms of performance and compile-time verification (although Java 
throws away much of that advantage by designing part of the language as 
if it were dynamically typed, forcing you to widen and narrow types for 
storage - the worst of both worlds, in many respects).

Giving up lists or arrays is a very bad idea.  An array has 
constant-time lookup, unlike a map.  A list can be constructed in O(n) 
time (by consing up), unlike a set.  Neither is an appropriate data 
type to use for a collection from which you want to frequently search 
based on a key, but they are useful and efficient when used correctly.

Primitive 'a set and ('a, 'b) map types in OCaml would certainly be 
possible, but as far as I can tell, the only advantages a primitive 
type would have over a library type would be the ability to construct 
an instance literally (construction is already easy using 
List/Array.fold_left over a list/array of items or tuples) and to 
deconstruct using pattern matching (whatever that would even mean - in 
any case, it would be inconsistent with what pattern matching currently 
does).

In Java, primitive sets and maps would perhaps have a bit more of an 
advantage, since currently library types are significantly weaker than 
primitive types (primitive arrays are the only parametrized type in 
Java).  But I think introducing more primitive types is the wrong 
solution (it would only make the Java type system even more 
inconsistent than it already is).  The right solution is to fix the 
language to make library types more powerful.  Introducing generics is 
one way to do this, and apparently what is being done.

> as index. This would automatically improve the O-behavior of the
> programs, ie. make them more scalable.

No, it would only improve the behavior of poorly written programs, and 
it would make make some programs perform worse.

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


  reply	other threads:[~2003-05-03  8:17 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-02 19:27 Eray Ozkural
2003-05-03  5:43 ` Mattias Waldau
2003-05-03  8:16   ` Ville-Pertti Keinonen [this message]
2003-05-03 14:12   ` Vitaly Lugovsky
2003-05-03 18:43     ` Mattias Waldau
2003-05-03 20:01       ` Eray Ozkural
2003-05-03 23:17       ` Eray Ozkural
2003-05-04  2:08       ` cashin
2003-05-04  4:08         ` alc
2003-05-04  5:32           ` Ed L Cashin
2003-05-04  6:46           ` [Caml-list] Two types of efficiency (Was Efficiency of 'a list) Mattias Waldau
2003-05-04  7:35             ` John Max Skaller
2003-05-04 11:52               ` Olivier Andrieu
2003-05-05 11:04                 ` John Max Skaller
2003-05-04 16:48               ` brogoff
2003-05-04  7:43             ` Ville-Pertti Keinonen
2003-05-04 12:50               ` Eray Ozkural
2003-05-04 12:48             ` Eray Ozkural
2003-05-05  7:31             ` Diego Olivier Fernandez Pons
2003-05-05 11:11               ` Mattias Waldau
2003-05-05 13:17                 ` John Max Skaller
2003-05-05 11:49               ` Eray Ozkural
2003-05-05 11:57               ` Yaron M. Minsky
2003-05-05 13:32                 ` John Max Skaller
2003-05-06  2:49                   ` Nicolas Cannasse
2003-05-06 12:30                     ` Diego Olivier Fernandez Pons
2003-05-07  2:05                       ` Nicolas Cannasse
2003-05-05 16:38                 ` Diego Olivier Fernandez Pons
2003-05-05 18:05                   ` Eray Ozkural
2003-05-06 13:28                     ` Diego Olivier Fernandez Pons
2003-05-13 11:35                   ` [Caml-list] Data Structure Libraries (was: Two types of efficiency) Oleg Trott
2003-05-04  7:55           ` [Caml-list] Efficiency of 'a list Ville-Pertti Keinonen
2003-05-04 10:56             ` Neel Krishnaswami
2003-05-04 12:56               ` Eray Ozkural
2003-05-04 13:35                 ` Falk Hueffner
2003-05-04 12:38           ` Eray Ozkural
2003-05-04  8:07         ` Ville-Pertti Keinonen
2003-05-04 15:54           ` Ed L Cashin
2003-05-05 23:52           ` Garry Hodgson
2003-05-03 20:03   ` Eray Ozkural
2003-05-03 21:13 ` Lauri Alanko
2003-05-03 22:03   ` Eray Ozkural

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=9BE14E24-7D3F-11D7-BCFA-000393863F70@exomi.com \
    --to=will@exomi.com \
    --cc=caml-list@inria.fr \
    --cc=erayo@cs.bilkent.edu.tr \
    --cc=mattias.waldau@abc.se \
    /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).