From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D8149BC57 for ; Sun, 14 Nov 2010 19:21:11 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnABANO330zRVdY2kGdsb2JhbACDQJBpjigIFQEBAQEJCQwHEQMfpDWJJIJUg2mJBwEBAwWBHYM1cwSEWoV9hXuDLw X-IronPort-AV: E=Sophos;i="4.59,196,1288566000"; d="scan'208";a="78596368" Received: from mail-bw0-f54.google.com ([209.85.214.54]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 Nov 2010 19:20:59 +0100 Received: by bwz2 with SMTP id 2so4631582bwz.27 for ; Sun, 14 Nov 2010 10:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=FV7qCddBiNPHPudTj34QM9yXtQIhiznnZZKjyBzTDSY=; b=C6NqdoN7qFAPHPjpXH2ml2ZmbltM3Du0AzO9wMaxNN+/asgs25vIPTQ/xol1zQYYJ7 Vk4ijQ0sC3XRR0RgsRIlW8JdvaSInyo4ocNdvZcmcZovfhgAUKfxOnq1MIIGt110np4s Mx55kHhrXiFwDNu+gKR9qLdxXsSlFWe2FwGZA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=dgQ7o4MkbxD58t73dWAXqVs0fA4eBkdyWgRLfdmhM08rIAQEx1yHriGOwC+QSiaQO3 kozgYBiyFspYA4LAqKLJb9+0W0lNvSwYOMEejPeQ0x2KdqgILlZVCc+3h6daou1aNwBn qMfFD7gBtTn52gCCnXSuQM9BoZACdj3b2tMrI= MIME-Version: 1.0 Received: by 10.204.102.206 with SMTP id h14mr5130788bko.204.1289758857891; Sun, 14 Nov 2010 10:20:57 -0800 (PST) Sender: till.varoquaux@gmail.com Received: by 10.204.50.200 with HTTP; Sun, 14 Nov 2010 10:20:57 -0800 (PST) In-Reply-To: <020e01cb80d6$0e52b890$2af829b0$@com> References: <1289372378510@names.co.uk> <020e01cb80d6$0e52b890$2af829b0$@com> Date: Sun, 14 Nov 2010 13:20:57 -0500 X-Google-Sender-Auth: GAyMyI2hFVKZz6_MSSL6abf3CTw Message-ID: Subject: Re: [Caml-list] Infix function composition operator From: Till Varoquaux To: Jon Harrop Cc: mark@proof-technologies.com, yminsky@gmail.com, arlen@noblesamurai.com, caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; infix:01 infix:01 combinator:01 ocaml:01 ocaml:01 cheers:01 yminsky:01 yminsky:01 beginner's:01 bug:01 beginner's:01 bug:01 forehead:98 10,:98 bounces:98 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 wrote: > A pipeline operator is usually preferred over function composition in imp= ure languages like OCaml and F# due to the value restriction. For example, = your example would be written in F# as: > > =C2=A0x |> op1 |> op2 |> op3 |> op4 |> op5 > > This style is very common in F#, particularly when dealing with collectio= ns. > > 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. =C2=A0Somehow, I usually find that code t= hat >> 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. =C2=A0But 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: >> =C2=A0 =C2=A0 =C2=A0 (op5 <<- op4 <<- op3 <<- op2 <<- op1) x >> Instead of: >> =C2=A0 =C2=A0 =C2=A0 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: >> =C2=A0 =C2=A0 =C2=A0 List.map (op2 <<- op1) xs >> Instead of: >> =C2=A0 =C2=A0 =C2=A0 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 >