From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 25FC0BC6E for ; Thu, 3 Apr 2008 16:08:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEABeC9EfAXQIn/2dsb2JhbACmFIV6giE X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="9153631" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Apr 2008 16:08:04 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m33E7xdn014079 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 3 Apr 2008 16:08:04 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnECACeB9EdC+Vyqc2dsb2JhbACRVwEMAwQFCRSUA4V5giE X-IronPort-AV: E=Sophos;i="4.25,599,1199660400"; d="scan'208";a="11028630" Received: from ug-out-1314.google.com ([66.249.92.170]) by mail3-smtp-sop.national.inria.fr with ESMTP; 03 Apr 2008 16:08:03 +0200 Received: by ug-out-1314.google.com with SMTP id k40so735211ugc.18 for ; Thu, 03 Apr 2008 07:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=0LrdO1hw1Tt1tdiSPU9UwgjfQ/Xq+y32SRZxzHwKkP0=; b=eXLn7lr6yzyjaCkHU+lawhBAqiP+eiRlGz4vE8PBe+hImGjtQx0LuhIM6K5uv7wUoDYXfP+zfmWsB1Le54tt8N3xAaMAYr2TPw5MRJLJrp9ghzKfeyYHTzBt5eT4wIKdV3AFj4T6PwEIwz9vvjZXPm7f+3fjUS3pqfke/5Wi2UY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=rjeFUdqOz3pdxSkNQ0+3ngRHjY5/PKil1zIF2X8iYXA+8vDau1tNno8lbt+IUePnVTrutDVCotXSp+u3pf5i/JtB2jK1pAtC2eU6AV3tCNQ0zMdjKNTsNeDS5Ju7rri4z2UNf2L4sMiFSdjiX8doRqwdAFIi4wNVgNBSBvCcGsA= Received: by 10.67.195.14 with SMTP id x14mr1454127ugp.40.1207231680194; Thu, 03 Apr 2008 07:08:00 -0700 (PDT) Received: by 10.67.95.3 with HTTP; Thu, 3 Apr 2008 07:08:00 -0700 (PDT) Message-ID: <906164100804030708p3e2788a0p29b69f4d46600622@mail.gmail.com> Date: Thu, 3 Apr 2008 16:08:00 +0200 From: "=?ISO-8859-2?Q?Micha=B3_Maciejewski?=" To: caml-list@inria.fr Subject: [Caml-list] Operators for Int64 and Int32 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Miltered: at concorde with ID 47F4E4BF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; michal:01 ocaml:01 ocaml:01 conciseness:01 casted:01 michal:01 beginners:01 parsing:01 integer:01 caml-list:01 short:01 int:01 int:01 expression:02 expression:02 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