From: "Michał Maciejewski" <michal.m.pl@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Operators for Int64 and Int32
Date: Thu, 3 Apr 2008 16:08:00 +0200 [thread overview]
Message-ID: <906164100804030708p3e2788a0p29b69f4d46600622@mail.gmail.com> (raw)
Hello,
I'm not sure whether i should post this message here or in beginners
area (which is probably dead for a long time).
I'm quite new to OCaml but recently I had to write a wave file parsing
application. I've decided to try OCaml instead of C++. The first
problem I've encountered was of course too short native Integer type
for representing some values in wave file header. So I was forced to
use int64 type instead.
Why not to add real operators in another module for non-native types
like int64 or int32 to standard library? It's not too elegant to
write:
Int64.add (Int64.mul (Int64.add a b) b) c;;
especially when you try to avoid exceeding a limit of 79 characters in
line. Putting a part of expression in the next line isn't also a good
idea due to readability and conciseness of code. For me writing some
expressions in that way took even 5 too 7 lines. Opening Int64 could
help, but then it would be possible to write:
of_int someint;;
It's not clear what type someint is casted to.
Besides modifying application is very difficult now. Imagine that we
want to change type of a, b and c to int. We have to change previous
expression to (a+b) * b + c it can be very hard for more complex
expressions.
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
let ( -^^) a b = Int64.sub a b
let ( *^^ ) a b = Int64.mul a b
let ( /^^ ) a b = Int64.div a b
let ( !^^ ) a = Int64.neg a
let ( %^^ ) a b = Int64.sub a (Int64.mul (Int64.div a b) b)
let ( +^ ) a b = Int32.add a b
let ( -^ ) a b = Int32.sub a b
let ( *^ ) a b = Int32.mul a b
let ( /^ ) a b = Int32.div a b
let ( !^ ) a = Int32.neg a
let ( %^ ) a b = Int32.sub a (Int32.mul (Int32.div a b) b)
the same for big_int
Note that It also preserves backward compatibility of OCaml.
Best regards
Michal Maciejewski
next reply other threads:[~2008-04-03 14:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-03 14:08 Michał Maciejewski [this message]
2008-04-03 15:24 ` David Allsopp
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=906164100804030708p3e2788a0p29b69f4d46600622@mail.gmail.com \
--to=michal.m.pl@gmail.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