caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Winfried Dreckmann <wd@lidingo.mail.telia.com>
To: "€ caml list" <caml-list@inria.fr>
Subject: [Caml-list] look operator
Date: Thu, 06 Jun 2002 12:01:02 +0200	[thread overview]
Message-ID: <B924FF7D.B917%wd@lidingo.mail.telia.com> (raw)

Dear everyone,

I can't resist to ask for people's opinion on a certain compromise between
imperative and functional programming which a found in the "numerix" library
of Michel Quercia. Of course, if you read this, Michel, I would be
particularly grateful for your own opinion.

It's about abstracting the ! operator by introducing a function

val look : tref -> t

which coerces a mutable object into a non-mutable one. Using this function
is dangerous because, with this function, the non-mutable type t is not
strictly non-mutable anymore. As the manual says, the result of "look r" is
volatile, it is only guaranteed to be valid until the next in-place
operation involving r. In my own experience, mistakes occur faster than
expected. But this is a great and elegant trick. Using "look", every single
function with arguments of type t, say

val add_in : tref -> t -> t -> unit,

replaces two or more functions which would otherwise be necessary, in this
case

val add_in1 : tref -> t -> t -> unit
val add_in2 : tref -> tref -> t -> unit
val add_in3 : tref -> tref -> tref -> unit

at least. This would certainly blow up the library to impractical
dimensions. Of course, overloading would help, and "look" might become
obsolete in this way.
However, I think the problem is not mainly about overloading, but about
reintroducing imperative features in an abstract and controlled way. I
could, for instance, also imagine an abstract assign operator

val set : tref -> t -> unit

where the contents of t is not copied but assigned to tref, and thus made
mutable, which could be useful in certain restricted ways.

My question to the caml list: Would you accept such constructions as decent
Caml programming, if applied carefully and only in cases where it allows
what is otherwise impossible (e. g. integrating mutable and non-mutable
objects as it is done in "numerix"). Or is it all just a silent
reintroduction of C pointers, and principally a bad thing?

Regards,
Winfried Dreckmann

-------------------
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:[~2002-06-06  9:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-06 10:01 Winfried Dreckmann [this message]
2002-06-06 10:58 ` Pixel
2002-06-07  8:02   ` Winfried Dreckmann
2002-06-06 15:08 ` Michel Quercia
2002-06-07  9:13   ` Winfried Dreckmann
2002-06-07 13:52     ` Michel Quercia
2002-06-08 11:23       ` Winfried Dreckmann

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=B924FF7D.B917%wd@lidingo.mail.telia.com \
    --to=wd@lidingo.mail.telia.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).