caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ville-Pertti Keinonen <will@exomi.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Array.filter (was Multi-keyed lookup table?)
Date: Mon, 11 Aug 2003 00:59:45 +0300	[thread overview]
Message-ID: <20030810215944.GA495@exomi.com> (raw)
In-Reply-To: <20030810204319.GA24968@roke.freak>

On Sun, Aug 10, 2003 at 10:43:19PM +0200, Michal Moskal wrote:

> It will bomb for large arrays. List.filter will not (BTW I don't
> understand why List.filter uses List.rev to be tail recursive and List.map
> does not).
> 
> Another thought would be to create bool array for predicate results, fill
> it, counting how much space do you need, and then create result array.
> 
> There is also third way, to run predicate twice, but it is not guaranteed
> safe in presence of side effects.

How about just creating a result array the same size as the original
(initially filled with item 0 of the original, special-cased for
empty arrays) and Array.sub:ing it for the result?  I'd think that
would be the obvious method.  Creating new instances of a value
shouldn't have any noticable side-effects.

Anyway, filter for arrays as well as strings is one of the more
useful things that might be desirable as part of the standard
library.  Functions for mapping and folding strings might also be
useful.  While the OCaml standard library is pretty good, it seems
fairly sparse compared to e.g. the functionality offered by Common
Lisp sequence functions, which work on lists, arrays and strings.

Implementing the necessary functionality is easy, but an advantage
of having more things as part of the standard lirbary would be the
reduction in LOC for OCaml solutions to programming tasks used to
compare programming languages (e.g. Prechelt's study, although that
didn't include OCaml).  OCaml isn't otherwise much more verbose
than Common Lisp (ignoring macros) or various scripting languages,
but for array and string manipulation, it can end up looking much
worse than it needs to.

Plenty of people who don't know many languages seem to believe that
static typing and/or explicit lexical scoping inevitably make
languages verbose, and that dynamically typed scripting languages
with idiosyncratic scoping rules and huge performance hits are the
only way around that.

-------------------
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-08-10 21:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-07 19:41 [Caml-list] Multi-keyed lookup table? Matt Gushee
2003-08-07 20:16 ` Brian Hurt
2003-08-07 21:49   ` Yaron Minsky
2003-08-07 22:26     ` John Max Skaller
     [not found]       ` <D4DBD8568F05D511A1C20002A55C008C11AC05E6@uswaumsx03medge.med.ge.com>
2003-08-08 21:30         ` Matt Gushee
2003-08-08 22:13           ` Brian Hurt
     [not found]           ` <005d01c35e51$7c927200$6628f9c1@zofo>
2003-08-09 16:57             ` [Caml-list] Array.filter (was Multi-keyed lookup table?) Matt Gushee
2003-08-09 18:48               ` ijtrotts
2003-08-10 19:53                 ` Michal Moskal
2003-08-10  2:34                   ` ijtrotts
2003-08-11  5:48                     ` David Brown
2003-08-10 18:53                       ` ijtrotts
2003-08-10 20:23                   ` Marcin 'Qrczak' Kowalczyk
2003-08-10  2:37                     ` ijtrotts
     [not found]                   ` <200308102222.16369.qrczak@knm.org.pl>
2003-08-10 20:43                     ` Michal Moskal
2003-08-10 21:59                       ` Ville-Pertti Keinonen [this message]
2003-08-10 20:55                 ` [Caml-list] Array.filter Jean-Baptiste Rouquier
2003-08-11  9:46                   ` Michal Moskal
2003-08-10 22:29                 ` [Caml-list] Array.filter (was Multi-keyed lookup table?) Shawn Wagner
2003-08-11 11:51           ` [Caml-list] Multi-keyed lookup table? Remi Vanicat
2003-08-07 22:19 ` John Max Skaller
2003-08-12  6:34   ` Florian Hars
2003-08-12  9:58     ` Michael Wohlwend

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=20030810215944.GA495@exomi.com \
    --to=will@exomi.com \
    --cc=caml-list@inria.fr \
    /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).