From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 91A1DBC57 for ; Tue, 16 Nov 2010 14:31:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvECAJ4W4kzRVdU0k2dsb2JhbACXbYpqCBUBAQEBCQkKCREDH6RAi3qFFYkHAQEDBYVGBIRYhgCDcoU4 X-IronPort-AV: E=Sophos;i="4.59,206,1288566000"; d="scan'208";a="78299850" Received: from mail-yw0-f52.google.com ([209.85.213.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Nov 2010 14:30:37 +0100 Received: by ywl5 with SMTP id 5so284701ywl.39 for ; Tue, 16 Nov 2010 05:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:subject:mime-version :content-type:from:in-reply-to:date:cc:content-transfer-encoding :message-id:references:to:x-mailer; bh=Cnb5wx50uTyGrbGxF08IU5vL7vhF58p5+v7AkYCDdC0=; b=PV1qY4Bw39KLyOwWiZ1mJgyzXyovXQCcGlqMVwptcOzfOlOMU0rmibGDHjPba2Xa2A NsLryUNZblrsm+iA85EGzRpX57f7dPB2bMrkzUHr/+Dt0JjL18zGYpsCA1yWn9t/ozt0 PAfZNccy1GMeK6gP+e3uxKdibnsyU1l6pB44I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; b=JRjxxpA/tY+EIXwmEWO3z4SYvI39lo38g63ki5LNxT9b7l5byLp/zI/p0oBEYJCBwi mq3gf5p3vlYMSCWWUS4rwIzbpekZwtXS2wh3K7ZFcgVnYUbGNzKNfEuA+rI9EOEhVBRK Lk6DFZ422SOy42j1W48/a+c12HArhM5+RqMS0= Received: by 10.42.241.137 with SMTP id le9mr6149920icb.24.1289914235532; Tue, 16 Nov 2010 05:30:35 -0800 (PST) Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mx.google.com with ESMTPS id fw4sm1105193ibb.13.2010.11.16.05.30.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Nov 2010 05:30:34 -0800 (PST) Sender: Jacques Garrigue Subject: Re: [Caml-list] Option functions (or lack thereof) + operator for composition Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: Date: Tue, 16 Nov 2010 22:30:30 +0900 Cc: caml-list@yquem.inria.fr Content-Transfer-Encoding: quoted-printable Message-Id: <97D1DAE6-9E21-4A87-87FC-72B3BCF2F071@gmail.com> References: To: Serge Le Huitouze X-Mailer: Apple Mail (2.1081) X-Spam: no; 0.00; ocaml:01 haskell:01 ocaml:01 val:01 val:01 lablgtk:01 grief:98 wrote:01 precedence:01 precedence:01 caml-list:01 functions:01 parentheses:01 parentheses:01 int:01 On 2010/11/16, at 20:27, Serge Le Huitouze wrote: > 1. Option type > **************** > It seems that there is no predefined function to test an "'a option" = for being > specifically "None" or "Some _". In ocaml you can compare at any type. So you can just write (!curSelectedRow <> None) which explains why there is no such function in the standard library. > 2. Operator for composition (and its precedence) > ******************************************************** > To get rid of many warnings, I wrapped some calls (the "connect" calls = of > my widgets) into "ignore (f x y)" statements. > I've no particular grief in using "ignore", but I find the parentheses > *really* annoying. >=20 > In Haskell, I would write "ignore $ f x y", which I find much lighter = weight. >=20 > I'm not familiar with operators and their precedence, but I wonder: is = it > possible to do something similar with OCaml? You can, but unfortunately $ does not have the right associativity. # let ($) f x =3D f x;; val ( $ ) : ('a -> 'b) -> 'a -> 'b =3D # ignore $ 1+1;; - : unit =3D () # succ $ succ 3;; - : int =3D 5 # succ $ succ $ succ 3;; Error: This expression has type int -> int but an expression was expected of type int As you can see, it works fine for one argument, but doesn't work if you = nest them. (Actually, this is a question of point of view, since you can use it in place of parentheses to sequence multiple arguments) If you want the compositionality, you can use something starting with @: # let (@@) f x =3D f x;; val ( @@ ) : ('a -> 'b) -> 'a -> 'b =3D # succ @@ succ @@ succ 3;; - : int =3D 6 Note however that there is a simpler way to circumvent the problem: use the "-w s" option on the command line, disabling the statement = warning. All my lablgtk code uses this flag :-) Jacques Garrigue=