From: oleg@pobox.com
To: caml-list@inria.fr
Subject: Re: Simple idea for making a function infix
Date: Mon, 13 Nov 2006 20:29:39 -0800 (PST) [thread overview]
Message-ID: <20061114042939.BD07FAC04@Adric.metnet.fnmoc.navy.mil> (raw)
Haskell's back-quote notation has a notable limitation as it applies
to identifiers only. That is, we gain infix identifiers rather than
infix expressions. As it turns out, we can obtain infix expressions
without any change of syntax or any backticks:
http://www.haskell.org/pipermail/haskell-prime/2006-March/000935.html
http://www.haskell.org/haskellwiki/Infix_expressions
It seems that the second solution of the above page is similar to the
one just proposed for OCaml. For ease of comparison, in Haskell, ($) is
defined as [x $ y = x y] and flip flips the order of the arguments.
The first solution on that page can be rendered in Ocaml as follows:
let (>--) x y = (x,y);;
let (<--) (x,f) y = f x y;;
Now we can write
# 3 >-- min <-- 4;;
- : int = 3
We gain not only infix identifiers but infix expressions as well:
let a = Array.make 3 'a';;
val a : char array = [|'a'; 'a'; 'a'|]
1 >-- Array.set a <-- 'b'; a;;
- : char array = [|'a'; 'b'; 'a'|]
so we can use even three-argument functions as sort of `infix'...
next reply other threads:[~2006-11-14 4:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-14 4:29 oleg [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-11-13 7:23 Keisuke Nakano
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=20061114042939.BD07FAC04@Adric.metnet.fnmoc.navy.mil \
--to=oleg@pobox.com \
--cc=caml-list@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