caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: Aaron Bohannon <bohannon@cis.upenn.edu>
Cc: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Having '<<', why to use '|>' ?
Date: Sat, 22 Sep 2007 17:22:45 +0200	[thread overview]
Message-ID: <1190474050-sup-2933@ausone.local> (raw)
In-Reply-To: <c413fcb70709200739q26cb7d8ena8d102790f5a3625@mail.gmail.com>

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 <fabrice.marchant@orange.fr>
> > 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


  reply	other threads:[~2007-09-22 15:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-20 14:39 Aaron Bohannon
2007-09-22 15:22 ` Nicolas Pouillard [this message]
2007-09-22 15:43   ` Daniel Bünzli
2007-09-22 23:55     ` Christian Stork
  -- strict thread matches above, loose matches on Subject: below --
2007-09-17 14:36 Fabrice Marchant
2007-09-17 18:59 ` [Caml-list] " Eric Cooper
2007-09-17 19:45   ` Fabrice Marchant
2007-09-17 22:24 ` Julien Moutinho
2007-09-18  5:39   ` Fabrice Marchant
2007-09-18  8:53     ` Julien Moutinho
2007-09-18  9:09       ` Julien Moutinho
2007-09-18 14:12       ` Fabrice Marchant
2007-09-18 16:42         ` Jon Harrop
2007-09-18 20:41           ` skaller
2007-09-19 19:49           ` Fabrice Marchant
2007-09-19 21:56             ` Vincent Aravantinos
2007-09-20 13:42             ` Ashish Agarwal
2007-09-20 18:37               ` Gabriel Kerneis
2007-09-21 20:58               ` Harrison, John R
2007-09-21 21:44                 ` Karl Zilles

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1190474050-sup-2933@ausone.local \
    --to=nicolas.pouillard@gmail.com \
    --cc=bohannon@cis.upenn.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).