Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you want seems to be a composition of binary and unary functions, like this:</p> <pre><code>compose :: (c -&gt; d) -&gt; (a -&gt; b -&gt; c) -&gt; (a -&gt; b -&gt; d) compose unary binary a b = unary (binary a b) </code></pre> <p>And you ask for a point-free version (without mentioning of <code>a</code> and <code>b</code> variables). Let's try and eliminate them one by one. We'll start with <code>b</code>, using the fact that <code>f (g x) = f . g</code>:</p> <pre><code>compose unary binary a = unary . binary a </code></pre> <p><code>a</code> is next. Let's desugar the expression first:</p> <pre><code>compose unary binary a = ((.) unary) (binary a) </code></pre> <p>And apply the same composition rule again:</p> <pre><code>compose unary binary = ((.) unary) . binary </code></pre> <p>This can be further written as:</p> <pre><code>compose unary = (.) ((.) unary) </code></pre> <p>Or even as</p> <pre><code>compose = (.) . (.) </code></pre> <p>Here, each <code>(.)</code> 'strips' an argument off the binary function and you need two of them because the function is binary. This idiom is very useful when generalised for any functor: <code>fmap . fmap</code> (note that <code>fmap</code> is equivalent to <code>.</code> when function is seen as a functor). This allows you to 'strip' any functor off, for example you can write:</p> <pre><code>incrementResultsOfEveryFunctionInTwoDimentionalList :: [[String -&gt; Integer]] -&gt; [[String -&gt; Integer]] incrementResultsOfEveryFunctionInTwoDimentionalList = fmap . fmap . fmap $ (+1) </code></pre> <p>So, your result becomes:</p> <pre><code>(fmap . fmap) nub (++) </code></pre> <p><em>Edit:</em></p> <p>I think I have found the answer my brain was trying to reproduce: <a href="https://stackoverflow.com/questions/5821089/haskell-function-composition-operator-of-type-cd-abc-abd/5822395#5822395">Haskell function composition operator of type (c→d) → (a→b→c) → (a→b→d)</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload