Browse thread
Re: Simple idea for making a function infix
- oleg@p...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-11-14 (04:30) |
From: | oleg@p... |
Subject: | Re: Simple idea for making a function infix |
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'...