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 994CEBC57 for ; Tue, 16 Nov 2010 16:18:24 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqgCADsv4kzRVdg0kGdsb2JhbACiDEsIFQEBAQEJCQwHEQMfpRqJYoIYhRIuiFkBAQMFhUYEiliJKg X-IronPort-AV: E=Sophos;i="4.59,206,1288566000"; d="scan'208";a="78394040" Received: from mail-qw0-f52.google.com ([209.85.216.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Nov 2010 16:18:23 +0100 Received: by qwd7 with SMTP id 7so110948qwd.39 for ; Tue, 16 Nov 2010 07:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=8OzpPIPn/MuChpBeOrVjda+tvszv68S7UEBnLsoHivE=; b=aA3iGfxaTl2dnhfUNz/TqGc2M71bAXIxPUMT+wkQ2JY2XRMCB1WEajv0rOffq5DHfD XpAziAm2eof/LP+inHCE7NeoixYFqLAriNeHnrb4oddxezvsf4potJ546eM7nmzme1pb p78uw3iewsdX74vD2d51aRSmc1GTRw6CH/gO0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=PSVvCW2OOCYXPp6tZxSQlmVtl3jzNo7KUxGksBemo2zxIOLDgDqYxRioWH8TkRxsws buf/DATqrjnlISq1fy4/QGnyN1PZf2+u5gwWN6RLf3fT3eZ7VVMyHvx1G/UAidh4/ypc BNoWt7t+KIaPxmK2sbn41rjmvtn4ew1s8RH1U= Received: by 10.229.232.205 with SMTP id jv13mr6336449qcb.68.1289920703277; Tue, 16 Nov 2010 07:18:23 -0800 (PST) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.253.135 with HTTP; Tue, 16 Nov 2010 07:18:02 -0800 (PST) In-Reply-To: <4CE294A1.5050100@elehack.net> References: <4CE294A1.5050100@elehack.net> From: bluestorm Date: Tue, 16 Nov 2010 16:18:02 +0100 X-Google-Sender-Auth: i5X5f6f8lM4_XvTJ6hqWjwSQejQ Message-ID: Subject: Re: [Caml-list] Option functions (or lack thereof) + operator for composition To: Michael Ekstrand Cc: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0016363b8d844eab2c04952d1141 X-Spam: no; 0.00; infix:01 ocaml:01 notations:01 ocaml:01 infix:01 notations:01 wrote:01 wrote:01 readable:01 readable:01 defines:01 defines:01 dmitry:01 dmitry:01 caml-list:01 --0016363b8d844eab2c04952d1141 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Nov 16, 2010 at 3:26 PM, Michael Ekstrand wrote: > > Batteries provides operators for things like this. It defines the '**>' > operator for function application; it's an odd name, but it has the > right associativity. As Dmitry mentioned, some override (&). Batteries > also provides composition operators |- and -|, and a pipeline operator > |> (opposite of **>). With that operator, you can write: > > f x y |> ignore > > thereby putting the emphasis on "f x y" and relegating "ignore" to a > cleanup at the end. > > - Michael (<|) as inverse of (|>) is also available. It doesn't have the "right" associativity, but you can easily use (f -| g -| h <| x) instead of (f **> g **> h **> x). Though I find the application-as-pipeline style quite readable in some cases, I think that in general it is more often superfluous than not. Besides, as mentioned recently on this list, overuse of the function composition operators (|-) and (-|) are also call for troubles with the value restriction. All in all, I think it's reasonable to stay conservative and not advertise funky binary operators too loudly. That said, domain-specific binary operators are certainly useful for readability in some contexts --- that's what an infix operator is anyway : an unreadable-by-design symbol that only get meaning by domain-specific conventions. Local open in, available by standard since OCaml 3.12, allow us to neatly encapsulate such domain-specific notations into OCaml modules. --0016363b8d844eab2c04952d1141 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Tue, Nov 16, 2010 at 3:26 PM, Michael Ekstran= d <michael@eleh= ack.net> wrote:
Batteries provides operators for things like this. =A0It defines the '*= *>'
operator for function application; it's an odd name, but it has the
right associativity. =A0As Dmitry mentioned, some override (&). =A0Batt= eries
also provides composition operators |- and -|, and a pipeline operator
|> (opposite of **>). =A0With that operator, you can write:

=A0 =A0f x y |> ignore

thereby putting the emphasis on "f x y" and relegating "igno= re" to a
cleanup at the end.

- Michael

(<|) as inverse of (|&g= t;) is also available. It doesn't have the "right" associativ= ity, but you can easily use (f -| g -| h <| x) instead of (f **> g **= > h **> x).

Though I find the application-as-pipeline style quite r= eadable in some cases, I think that in general it is more often superfluous= than not. Besides, as mentioned recently on this list, overuse of the func= tion composition operators (|-) and (-|) are also call for troubles with th= e value restriction.
All in all, I think it's reasonable to stay conservative and not a= dvertise funky binary operators too loudly.

That s= aid, domain-specific binary operators are certainly useful for readability = in some contexts --- that's what an infix operator is anyway : an unrea= dable-by-design symbol that only get meaning by domain-specific conventions= . Local open in, available by standard since OCaml 3.12, allow us to neatly= encapsulate such domain-specific notations into OCaml modules.
--0016363b8d844eab2c04952d1141--