* [Caml-list] pipe input short syntax idea @ 2015-10-10 13:52 Nils Becker 2015-10-10 14:11 ` octachron 2015-10-11 1:09 ` Martin DeMello 0 siblings, 2 replies; 8+ messages in thread From: Nils Becker @ 2015-10-10 13:52 UTC (permalink / raw) To: caml-list hi, just an idea for a short notation which might be appealing: (|> f |> g |> ... ) as abbreviation for (fun x -> x |> f |> g |> ...) (|> f) would be just f. in other words a it's function composition using |> . it looks intuitive to me. but of course it could be a bad idea for a lot of reasons. n, ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-10 13:52 [Caml-list] pipe input short syntax idea Nils Becker @ 2015-10-10 14:11 ` octachron 2015-10-11 0:19 ` Yotam Barnoy 2015-10-11 1:09 ` Martin DeMello 1 sibling, 1 reply; 8+ messages in thread From: octachron @ 2015-10-10 14:11 UTC (permalink / raw) To: caml-list Hi, If you just want a short notation for (fun x -> x |> f |> g |> ...), why not simply define a composition operator? With let (->-) f g x = x |> f |> g;; you can rewrite the previous expression as f ->- g ->- h ... I personally don't think that there is any need for a special syntax here. At the same time, it could be nice if there was a standardized name for composition operators. —octachron. Le 10/10/15 15:52, Nils Becker a écrit : > hi, > > just an idea for a short notation which might be appealing: > > (|> f |> g |> ... ) as abbreviation for (fun x -> x |> f |> g |> ...) > > (|> f) would be just f. > > in other words a it's function composition using |> . it looks intuitive > to me. but of course it could be a bad idea for a lot of reasons. > > n, > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-10 14:11 ` octachron @ 2015-10-11 0:19 ` Yotam Barnoy 2015-10-11 0:56 ` Ian Zimmerman 0 siblings, 1 reply; 8+ messages in thread From: Yotam Barnoy @ 2015-10-11 0:19 UTC (permalink / raw) To: octachron; +Cc: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 1404 bytes --] I definitely agree that we need a standardized composition operator. It's so much nicer to have one in the standard library rather than having to define our own. I personally use |- but I would be open to anything of equal length. On Sat, Oct 10, 2015 at 10:11 AM, octachron <octa@polychoron.fr> wrote: > Hi, > If you just want a short notation for (fun x -> x |> f |> g |> ...), > why not simply define a composition operator? > > With > let (->-) f g x = x |> f |> g;; > you can rewrite the previous expression as f ->- g ->- h ... > I personally don't think that there is any need for a special syntax here. > > At the same time, it could be nice if there was a standardized name for > composition operators. > > —octachron. > > Le 10/10/15 15:52, Nils Becker a écrit : > > hi, >> >> just an idea for a short notation which might be appealing: >> >> (|> f |> g |> ... ) as abbreviation for (fun x -> x |> f |> g |> ...) >> >> (|> f) would be just f. >> >> in other words a it's function composition using |> . it looks intuitive >> to me. but of course it could be a bad idea for a lot of reasons. >> >> n, >> >> >> > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 2260 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-11 0:19 ` Yotam Barnoy @ 2015-10-11 0:56 ` Ian Zimmerman 2015-10-11 1:01 ` Yotam Barnoy 0 siblings, 1 reply; 8+ messages in thread From: Ian Zimmerman @ 2015-10-11 0:56 UTC (permalink / raw) To: caml-list On 2015-10-10 20:19 -0400, Yotam Barnoy wrote: > I definitely agree that we need a standardized composition operator. It's > so much nicer to have one in the standard library rather than having to > define our own. I personally use |- but I would be open to anything of > equal length. What's wrong with SML's "o"? :-P -- Please *no* private copies of mailing list or newsgroup messages. Rule 420: All persons more than eight miles high to leave the court. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-11 0:56 ` Ian Zimmerman @ 2015-10-11 1:01 ` Yotam Barnoy 0 siblings, 0 replies; 8+ messages in thread From: Yotam Barnoy @ 2015-10-11 1:01 UTC (permalink / raw) To: Ian Zimmerman, Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 1084 bytes --] That's... actually a really neat idea! Sure, it would need a parsing hack to work (same as land, lxor etc), but having an operator as light as haskell's dot (.) would be awesome! And do you ever use o as a variable? We could check if anything on opam uses o. I'd seriously be up for it myself. On Sat, Oct 10, 2015 at 8:56 PM, Ian Zimmerman <itz@buug.org> wrote: > On 2015-10-10 20:19 -0400, Yotam Barnoy wrote: > > > I definitely agree that we need a standardized composition operator. It's > > so much nicer to have one in the standard library rather than having to > > define our own. I personally use |- but I would be open to anything of > > equal length. > > What's wrong with SML's "o"? > > :-P > > -- > Please *no* private copies of mailing list or newsgroup messages. > Rule 420: All persons more than eight miles high to leave the court. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 1877 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-10 13:52 [Caml-list] pipe input short syntax idea Nils Becker 2015-10-10 14:11 ` octachron @ 2015-10-11 1:09 ` Martin DeMello 2015-10-11 1:31 ` Yotam Barnoy 1 sibling, 1 reply; 8+ messages in thread From: Martin DeMello @ 2015-10-11 1:09 UTC (permalink / raw) To: Nils Becker; +Cc: caml-list [-- Attachment #1: Type: text/plain, Size: 782 bytes --] F# defines composition operators >> and <<: http://theburningmonk.com/2011/09/fsharp-pipe-forward-and-pipe-backward/ martin On Sat, Oct 10, 2015 at 6:52 AM, Nils Becker < nils.becker@bioquant.uni-heidelberg.de> wrote: > hi, > > just an idea for a short notation which might be appealing: > > (|> f |> g |> ... ) as abbreviation for (fun x -> x |> f |> g |> ...) > > (|> f) would be just f. > > in other words a it's function composition using |> . it looks intuitive > to me. but of course it could be a bad idea for a lot of reasons. > > n, > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > [-- Attachment #2: Type: text/html, Size: 1665 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-11 1:09 ` Martin DeMello @ 2015-10-11 1:31 ` Yotam Barnoy 2015-10-11 8:36 ` Petter A. Urkedal 0 siblings, 1 reply; 8+ messages in thread From: Yotam Barnoy @ 2015-10-11 1:31 UTC (permalink / raw) To: Martin DeMello; +Cc: Nils Becker, caml-list [-- Attachment #1: Type: text/plain, Size: 1444 bytes --] Interesting, but seems like overkill to me personally. I'm ok with @@ and |> (which already breaks F#'s convention, since @@ would be <| in F#. What's the reason we went with @@ instead again?). Function composition is potentially more confusing, and I think keeping it with a consistent associativity direction (that being the direction of normal function application from right to left) has value. So I'm personally sort-of ok with <<, but once you suggest something as beautifully concise as o, I'm overwhelmed by the convenience factor. On Sat, Oct 10, 2015 at 9:09 PM, Martin DeMello <martindemello@gmail.com> wrote: > F# defines composition operators >> and <<: > > http://theburningmonk.com/2011/09/fsharp-pipe-forward-and-pipe-backward/ > > martin > > On Sat, Oct 10, 2015 at 6:52 AM, Nils Becker < > nils.becker@bioquant.uni-heidelberg.de> wrote: > >> hi, >> >> just an idea for a short notation which might be appealing: >> >> (|> f |> g |> ... ) as abbreviation for (fun x -> x |> f |> g |> ...) >> >> (|> f) would be just f. >> >> in other words a it's function composition using |> . it looks intuitive >> to me. but of course it could be a bad idea for a lot of reasons. >> >> n, >> >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > > [-- Attachment #2: Type: text/html, Size: 2782 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] pipe input short syntax idea 2015-10-11 1:31 ` Yotam Barnoy @ 2015-10-11 8:36 ` Petter A. Urkedal 0 siblings, 0 replies; 8+ messages in thread From: Petter A. Urkedal @ 2015-10-11 8:36 UTC (permalink / raw) To: Yotam Barnoy; +Cc: Martin DeMello, Nils Becker, caml-list [-- Attachment #1: Type: text/plain, Size: 1713 bytes --] 2015-10-11 3:31 GMT+02:00 Yotam Barnoy <yotambarnoy@gmail.com>: > Interesting, but seems like overkill to me personally. I'm ok with @@ and |> > (which already breaks F#'s convention, since @@ would be <| in F#. What's > the reason we went with @@ instead again?). I think it's really useful that @@ is right associative. There was a post [1] arguing the opposite for Haskell's $, but that presumes we have a composition operator at a higher precedence level, and that OCaml transforms it into a plain application, for efficiency. > Function composition is > potentially more confusing, and I think keeping it with a consistent > associativity direction (that being the direction of normal function > application from right to left) has value. So I'm personally sort-of ok with > <<, but once you suggest something as beautifully concise as o, I'm > overwhelmed by the convenience factor. For composition, associativity wouldn't matter as the operation itself is associative. Except from performance. According to the attached benchmark, the normal composition operator should be right associative, at least on my computer. Then reversed composition should be left associative. But it's not a big difference (esp. considering that most uses are binary or ternary) and I'm not sure whether it applies across compiler versions. I expected the opposite result. I'm not thrilled about using a single letter o as an operator. If we want ∘, we should use that, though some might not like to deal with input methods. I've use *< and *> for some time, thinking of * as the closest cousin of ∘. [1] https://mail.haskell.org/pipermail/haskell-cafe/2006-February/014237.html [-- Attachment #2: composition_associativity.ml --] [-- Type: text/x-ocaml, Size: 572 bytes --] open Printf (* open Infix *) let ( *< ) f g x = f (g x) let ( **< ) f g x = f (g x) let test1 f g = f *< g *< f *< g *< f *< g *< f *< g *< f *< g let test2 f g = f **< g **< f **< g **< f **< g **< f **< g **< f **< g let clock () = Unix.((times ()).tms_utime) let () = let t0 = clock () in let x = ref 0 in for i = 0 to 1000000 do x := test1 succ pred !x done; let t1 = clock () in for i = 0 to 1000000 do x := test2 succ pred !x done; let t2 = clock () in printf "Left associative: %g\nRight associative: %g\n" (t1 -. t0) (t2 -. t1) ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-10-11 8:36 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-10-10 13:52 [Caml-list] pipe input short syntax idea Nils Becker 2015-10-10 14:11 ` octachron 2015-10-11 0:19 ` Yotam Barnoy 2015-10-11 0:56 ` Ian Zimmerman 2015-10-11 1:01 ` Yotam Barnoy 2015-10-11 1:09 ` Martin DeMello 2015-10-11 1:31 ` Yotam Barnoy 2015-10-11 8:36 ` Petter A. Urkedal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox