[Haskell-cafe] Composition and type magic
Stere0id
stereoid at zankapfel.org
Tue Feb 24 08:15:13 UTC 2015
On 24.02.2015 06:57, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote:
> Thanks.
> You've given me a good exercise in equational reasoning.
>
> I'm studying such things because I might start studying combinatory logic
> (Smullyan's mockingbird book) soon.
> It's a good exercise for the mind, and is very enjoyable with pencil &
> paper.
> Can you give me some more patterns like transducers (foldl foldl) and the
> dot-dot-dot ( boobies, in your words :) ) example?
>
> Thanks once again.
>
> On 24 February 2015 at 08:57, Michael Orlitzky <michael at orlitzky.com> wrote:
>
>> On 02/23/2015 10:11 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote:
>>> Hi everyone,
>>>
>>> I defined a function for discrete convolution, i.e
>>>
>>> conv xs = sum . zipWith (*) xs . reverse
>>>
>>> And I was wondering, can it be done without explicitly passing in the xs
>>> (eta-reduction)?
>>
>> Ehhhhhhhhhh this will work:
>>
>> conv = (sum .) . (. reverse) . zipWith (*)
>>
>> But it's so much easier to understand without all the boobies operators:
>>
>> conv xs ys = sum $ zipWith (*) xs (reverse ys)
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
You might be interested in the pointfree [1] tool, which can convert
lambda expressions to pointfree versions automatically. Allthough I also
find the more complex ones, as in this case, rather obscure.
I like you initial version best:
conv xs = sum . zipWith (*) xs . reverse
[1] http://hackage.haskell.org/package/pointfree
More information about the Haskell-Cafe
mailing list