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.7 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E871EBC6B for ; Thu, 20 Sep 2007 16:38:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAG0j8kZA6aayi2dsb2JhbACOFQEBAQgEBBERBQ X-IronPort-AV: E=Sophos;i="4.20,278,1186351200"; d="scan'208";a="16481967" Received: from py-out-1112.google.com ([64.233.166.178]) by mail4-smtp-sop.national.inria.fr with ESMTP; 20 Sep 2007 16:39:40 +0200 Received: by py-out-1112.google.com with SMTP id u52so980599pyb for ; Thu, 20 Sep 2007 07:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; bh=cmG66sAENCE4tY9nlzo4BnGUh4LTA+3cCOzBXf+Ecss=; b=SziTP6GClpL+OT5dT41M9+KnHDOalB6JrgnvUPdcNTVopzOolzK5gXEbP11zD+TJD6N/hJALreTEVna8zoQDHDNbE574ncc9tzLiTDUB6yHhdWBbOMNn3YGCIokkM+V27vcjPeCy2OsGKQ3EoyTwWTq4aA6q9igPfWVBEmM6gGo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=JXb4EEHV1fMCHn/UOphfU2UEPIM9BrU0Su9eJUWVYKnO7j6V8OAgdN3BclJgUll7TvKA3iPDUR1c0wZ6Q194bfIJpvK+isM7/YvA5jabsHDkqsaLLUD4D1Ae79LG5KbF7oqGqXrjTzHsG9dIEGpslv9KjTVStDWiLe9/fC0JJls= Received: by 10.65.119.14 with SMTP id w14mr4283724qbm.1190299176452; Thu, 20 Sep 2007 07:39:36 -0700 (PDT) Received: by 10.65.205.4 with HTTP; Thu, 20 Sep 2007 07:39:36 -0700 (PDT) Message-ID: Date: Thu, 20 Sep 2007 10:39:36 -0400 From: "Aaron Bohannon" Sender: aaron678@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Having '<<', why to use '|>' ? MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: ee63bad7f676cd4f X-Spam: no; 0.00; camlp:01 infix:01 haskell:01 notations:01 infix:01 sprintf:01 monadic:01 flatten:01 camlp:01 avoided:01 parser:01 'o':01 symmetric:01 cheers:01 upenn:01 It's too bad that $ is reserved for Camlp4. It would be a natural choice for infix application since that's what Haskell uses. 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