caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: <caml-list@inria.fr>
Subject: RE: [Caml-list] Operators for Int64 and Int32
Date: Thu, 3 Apr 2008 16:24:21 +0100	[thread overview]
Message-ID: <002201c8959e$cb9e74f0$017ca8c0@countertenor> (raw)
In-Reply-To: <906164100804030708p3e2788a0p29b69f4d46600622@mail.gmail.com>

I totally agree that expressions manipulating Int64 and Int32 quickly become
illegible, however I don't agree with your suggestions...

> Int64.add (Int64.mul (Int64.add a b) b) c;;
>
> especially when you try to avoid exceeding a limit of 79 characters in
> line. 

OT: May I politely suggest that perhaps your coding standards could do with
updating to mitigate part of this. Unless you're still on an 80x25 character
terminal limiting yourself to 79 characters per line is pretty archaic. We
use 150 character max line limit (and print in landscape if necessary)
because every display we work on has a resolution of at least 1280x1024.

> The best solutions to those problem would be in my opinion to add
> something like this to standard library (to new module):
>
> let ( +^^ ) a b = Int64.add a b
<snip>
>
> let ( +^ ) a b = Int32.add a b
<snip>

My problem with this, as someone who writes a lot of OCaml but uses Int64
and Int32 rarely, is that these operators aren't clearly anything to do with
Int64 or Int32 in terms of their "names" (symbols). Defining funny strings
of symbols to get around the (intentional) limitations of not having
operator overloading is IMHO not something that should be in the standard
library. If you're writing code that uses the operations so frequently that
clarity requires aliases then your code will be much more readable if you
have:

(* other, non-Int64/32 code *)

let ( +^^ ) a b = ...
and ( -^^ ) a b = ...
...
in
  (*
   * A block of code of reasonable length that makes extremely dense use of
   * the above operators.
   *)

(* Perhaps more non-Int64/32 code *)

That said, you could do it your way and my way with the aid of pa_openin
which allows you to open a module just within a block of code which would
save writing out the operators every time - for *your* code.

cout << "Adding lots of strange-looking operators (even in sub-modules \
that would need to be opened) to the StdLib is one step down the slippery \
slope to C(++) operator hell..."

Just my two pennyworth...


David


  reply	other threads:[~2008-04-03 15:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-03 14:08 Michał Maciejewski
2008-04-03 15:24 ` David Allsopp [this message]
2008-04-03 15:44   ` Bünzli Daniel
2008-04-03 19:00   ` David Thomas
2008-04-03 19:50   ` Michał Maciejewski
2008-04-03 22:22     ` Jon Harrop
2008-04-03 17:15 ` Richard Jones
2008-04-03 20:17 ` Erik de Castro Lopo
2008-04-03 20:39   ` Michał Maciejewski
2008-04-03 22:02     ` Erik de Castro Lopo
2008-04-03 22:17   ` Richard Jones
2008-04-04  1:47     ` Erik de Castro Lopo
2008-04-04 17:58       ` Adrien
2008-04-04 21:07         ` Richard Jones
2008-04-06 17:34           ` Adrien

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='002201c8959e$cb9e74f0$017ca8c0@countertenor' \
    --to=dra-news@metastack.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).