Browse thread
Re: [Caml-list] Infix function composition operator
-
mark@p...
-
Jon Harrop
- Till Varoquaux
-
Jon Harrop
[
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: | 2010-11-14 (18:21) |
From: | Till Varoquaux <till@p...> |
Subject: | Re: [Caml-list] Infix function composition operator |
Thank you jon; this was a very insightful answer. Brought me one of those palm forehead moments: Most novice programmers don't understand the value restriction and having an infix function composition operator in your standard library is like throwing them under the bus. In general I find that this (value restriction) is a problem I often hit when writing combinator libraries in ocaml. On Wed, Nov 10, 2010 at 7:51 AM, Jon Harrop <jonathandeanharrop@googlemail.com> wrote: > A pipeline operator is usually preferred over function composition in impure languages like OCaml and F# due to the value restriction. For example, your example would be written in F# as: > > Â x |> op1 |> op2 |> op3 |> op4 |> op5 > > This style is very common in F#, particularly when dealing with collections. > > Cheers, > Jon. > >> -----Original Message----- >> From: caml-list-bounces@yquem.inria.fr [mailto:caml-list- >> bounces@yquem.inria.fr] On Behalf Of mark@proof-technologies.com >> Sent: 10 November 2010 07:00 >> To: yminsky@gmail.com; arlen@noblesamurai.com >> Cc: caml-list@inria.fr >> Subject: Re: [Caml-list] Infix function composition operator >> >> on 10/11/10 3:45 AM, yminsky@gmail.com wrote: >> >> > This is probably a minority opinion, but I have written and read >> quite a >> lot >> > of OCaml code over the years, and I've seen surprisingly few >> effective >> uses >> > of the composition operator. Â Somehow, I usually find that code that >> avoids >> > it is simpler and easier to read. >> >> I agree that using a composition operator can make the code obtuse, and >> so >> should not be overused. Â But it's incredibly useful for certain >> situations: >> >> 1) If you are performing a long chain of composed operations, it avoids >> nested bracketing piling up. >> >> For example: >> Â Â Â (op5 <<- op4 <<- op3 <<- op2 <<- op1) x >> Instead of: >> Â Â Â op5 (op4 (op3 (op2 (op1 x)))) >> >> This sort of thing happens quite a lot in certain applications, e.g. in >> language processing, to get at subexpressions. >> >> 2) Creating an anonymous function to be passed as an argument, it >> avoids >> explicitly mentioning arguments of that function. >> >> This sort of thing can happen a lot in functional programming >> generally. >> >> For example: >> Â Â Â List.map (op2 <<- op1) xs >> Instead of: >> Â Â Â List.map (fun x -> op2 (op1 x)) xs >> >> Mark Adams >> >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >