[Haskell-cafe] Syntax proposal for "reverse apply"/"pipeline apply" (flip ($))

Ben Foppa benjamin.foppa at gmail.com
Thu Apr 17 18:38:22 UTC 2014


Can we argue about the fixity for (<&>)? I've always it as infixl 4, to mix
it in with other applicative operators, e.g.:

(:) <$> fx <*> fl

becomes

fx <&> (:) <*> fl


On Thu, Apr 17, 2014 at 2:05 PM, Clark Gaebel <cgaebel at uwaterloo.ca> wrote:

> Last I checked,
>
> (&) = flip ($)
>
> is both shorter to type, and more explicit than:
>
> import Control.Apply.Reverse
>
>   - Clark
>
>
> On Thu, Apr 17, 2014 at 2:03 PM, Hans Höglund <hans at hanshoglund.se> wrote:
>
>>
>> There is also is my humble attempt to standardize the (&) formulation:
>>
>> http://hackage.haskell.org/package/reverse-apply
>>
>> As you can see, these definitions now mirror those in 'lens' exactly. I
>> see no reason why this definition should not move to base. IMHO, the
>> Diagrams definition is a very specific one based on the needs of that EDSL,
>> while the lens formulation is the expected one.
>>
>> Mvh,
>> Hans
>>
>>
>> On 17 apr 2014, at 14:00, haskell-cafe-request at haskell.org wrote:
>>
>> Message: 1
>> Date: Wed, 16 Apr 2014 16:49:31 -0700
>> From: Dan Burton <danburton.email at gmail.com>
>> To: Alexey Muranov <alexey.muranov at gmail.com>
>> Cc: haskell-cafe <haskell-cafe at haskell.org>
>> Subject: Re: [Haskell-cafe] Syntax proposal for "reverse
>> apply"/"pipeline apply" (flip ($))
>> Message-ID:
>> <CALSygwf0wdBbrfQeED_raWjNfttYaX7pwDTzmBTTHaUqEkX5rg at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>>
>> In the "lens" package, this is (&) at infixl 1. In the "diagrams" package,
>> this is (#) at infixl 8. You're certainly not the first to want this, but
>> nobody can ever agree what it should be called or what fixity it should
>> have. You can always just define it yourself.
>>
>> -- Dan Burton
>>
>>
>> On Wed, Apr 16, 2014 at 3:25 PM, Alexey Muranov <alexey.muranov at gmail.com
>> >wrote:
>>
>> Hello,
>>
>>
>> i am completely new to Haskell, but i am somewhat fascinated by
>>
>> lambda-calculus and programming.
>>
>>
>> For whatever it is worth, i would like to propose for discussion a syntax
>>
>> for "(flip ($))" operation in Haskell.
>>
>>
>> I think that a good syntax would be "|^", for example:
>>
>>
>>     square x = x * x
>>
>>    y = 3 |^ square             -- y == 9
>>
>>
>>
>> Explanation:
>>
>>
>> * i would have suggested just ^, but it would conflict with number
>>
>> exponentiation,
>>
>>
>> * it is rather common in mathematics to write function application in
>>
>> exponential notation:  x ^ f  instead of  f(x), especially if  f  is an
>>
>> automorphism of some structure,
>>
>>
>> * (flip ($)) is exactly the exponentiation of Church numerals,
>>
>>
>> * in "The calculi of lambda-conversion", Alonzo Church uses the
>>
>> "shorthand" notation "[N^M]" for "(MN)", where M and N are lambda-terms.
>>
>>
>> * I am probably not the only person missing the ability to apply functions
>>
>> from the right:
>>
>>
>>
>> http://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-forward-operator
>>
>>
>> Well, other notations i've thought of are "\^" and "~$".
>>
>>
>> Alexey.
>>
>> _______________________________________________
>>
>> Haskell-Cafe mailing list
>>
>> Haskell-Cafe at haskell.org
>>
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://www.haskell.org/pipermail/haskell-cafe/attachments/20140416/818eebe7/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 16 Apr 2014 16:56:37 -0700 (PDT)
>> From: Alexey Muranov <alexey.muranov at gmail.com>
>> To: haskell-cafe at googlegroups.com
>> Cc: haskell-cafe <haskell-cafe at haskell.org>
>> Subject: Re: [Haskell-cafe] Syntax proposal for "reverse
>> apply"/"pipeline apply" (flip ($))
>> Message-ID: <0569e94e-44b8-44a0-abe3-4bd7d80b2ed4 at googlegroups.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>>
>> On Thursday, April 17, 2014 1:49:31 AM UTC+2, Dan Burton wrote:
>>
>> In the "lens" package, this is (&) at infixl 1. In the "diagrams" package,
>>
>>
>> this is (#) at infixl 8. You're certainly not the first to want this, but
>>
>>
>> nobody can ever agree what it should be called or what fixity it should
>>
>> have. You can always just define it yourself.
>>
>>
>>
>> (#) does not look too bad either.
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://www.haskell.org/pipermail/haskell-cafe/attachments/20140416/ccada62f/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Wed, 16 Apr 2014 18:41:01 -0700
>> From: Dan Burton <danburton.email at gmail.com>
>> To: Alexey Muranov <alexey.muranov at gmail.com>
>> Cc: haskell-cafe <haskell-cafe at haskell.org>,
>> haskell-cafe at googlegroups.com
>> Subject: Re: [Haskell-cafe] Syntax proposal for "reverse
>> apply"/"pipeline apply" (flip ($))
>> Message-ID:
>> <CALSygwdyxhNLafMZDm15iVzPO4qYytdC7q2fDRhabNWJ4Vrb=g at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>>
>> Interesting. I've never seen it proposed as right-associative before. Just
>> FYI, the implementation is as simple as this:
>>
>> infixr 1 |^
>> (|^) :: a -> (a -> b) -> b
>> x |^ f = f x
>>
>> Then you can write:
>>
>> 3 |^ 2 |^ (^) -- produces 2^3 = 8
>>
>> It seems very odd to me. I don't know why you'd want to apply the
>> arguments
>> backwards one by one. However, lens and diagrams both provide examples
>> where you want to start with a value and apply functions "forwards" one by
>> one, which is why their corresponding operators are left-associative.
>>
>> -- Dan Burton
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
>
> --
> Clark.
>
> Key ID     : 0x78099922
> Fingerprint: B292 493C 51AE F3AB D016  DD04 E5E3 C36F 5534 F907
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140417/84018d4f/attachment.html>


More information about the Haskell-Cafe mailing list