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=1.1 required=5.0 tests=AWL,SPF_NEUTRAL 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 AAE40BC6B for ; Sat, 22 Sep 2007 17:21:33 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.20,286,1186351200"; d="scan'208";a="1576609" Received: from peray.inria.fr (HELO ausone.inria.fr) ([128.93.8.98]) by mail2-relais-roc.national.inria.fr with SMTP; 22 Sep 2007 17:23:13 +0200 Received: by ausone.inria.fr (sSMTP sendmail emulation); Sat, _d Sep 2007 17:22:45 +0200 From: "Nicolas Pouillard" Cc: caml-list Subject: Re: [Caml-list] Having '<<', why to use '|>' ? To: Aaron Bohannon References: In-Reply-To: Date: Sat, 22 Sep 2007 17:22:45 +0200 Message-Id: <1190474050-sup-2933@ausone.local> User-Agent: Sup/0.1 Content-Type: text/plain; charset=utf-8 X-Spam: no; 0.00; camlp:01 infix:01 haskell:01 ocaml:01 haskell:01 ocaml:01 notations:01 infix:01 sprintf:01 monadic:01 flatten:01 camlp:01 avoided:01 parser:01 'o':01 Excerpts from Aaron Bohannon's message of Thu Sep 20 16:39:36 +0200 2007: > It's too bad that $ is reserved for Camlp4. It would be a natural > choice for infix application since that's what Haskell uses. The old and deprecated `&' operator do perfectly the job. Indeed the OCaml `&' operator have the associativity and a precedence close to the Haskell `$' than what can do the OCaml `$'. For some more information: http://caml.inria.fr/mantis/view.php?id=2415 > I have used the following notations for function composition in the past: > > let ( |> ) f g x = g (f x) > let ( <| ) f g x = f (g x) > > I am glad that those are natural to other people, too. I also like to > be able to compose predicate functions. Does anyone have better ideas > than what is below? > > let ( &&& ) p q x = p x && q x > let ( ||| ) p q x = p x || q x > let ( !!! ) p x = not (p x) > > One can also define "%" to do Python-esque string construction, > although using it with more than one argument requires a nice operator > for infix application. > > let ( % ) f x = Format.sprintf f x > > "(%c, %n, %s, %b)" % 'a' @@ 12 @@ "hello" @@ true > > "@@" isn't looking so nice to me here. > > And an operator that is very useful (almost essential) in certain > situations is a monadic "bind" in the list monad: > > let ( >>@ ) xs f = List.flatten (List.map f xs) > > I chose "@" as a reference to the list concatenation operator. > > Are there any others? Are there better ideas or warnings about the > ones I have here? > > -Aaron > > > ---------- Forwarded message ---------- > > From: Fabrice Marchant > > To: caml-list@yquem.inria.fr > > Date: Tue, 18 Sep 2007 16:12:46 +0200 > > Subject: Re: [Caml-list] Having '<<', why to use '|>' ? > > Thanks Julien ! > > > > > Have a look at this: > > > http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#infix-symbol > > > With the keywords below. > > "Note that the following identifiers are keywords of the Camlp4 extensions and should be avoided for compatibility reasons. > > > > parser << <: >> $ $$ $: > > " > > So no doubt, I'll edit my old programs and replace "<<". > > > > > > ... a composition operator ... ( <<< ) ? > > > > What else ? > > > > > I would personally double the '@': > > > let (@@) f g x = f @ g x > > > > ( or f (g x) : it is practically the same thing. ) > > > > A 3 chars operator (<<<) doesn't look smart. Simpler is better. > > However, about (@@), I preferred to see the direction of the asymmetric composition operator. > > ( <| ) instead of ( << ) ? Is this a possible idea ? > > > > But maybe your idea is good. Maths use a kind of small 'o' : (f o g) (x) = f (g (x)). > > It's symmetric like (@@), and that doesn't raise any problem. > > > > Cheers, > > > > Fabrice > -- Nicolas Pouillard aka Ertai