title: Haskell Absolute Difference Using Function Compsition
body: <p>I am trying to define a function to find the absolute difference of two numbers, such that both</p>
  
  <pre><code>absoluteDifference 2 5
  absoluteDifference 5 2
  </code></pre>
  
  <p>return <code>3</code>.</p>
  
  <p>Here is my best effort so far:</p>
  
  <pre><code>absoluteDifference :: Num a =&gt; a -&gt; a -&gt; a
  absoluteDifference = abs . (-)
  </code></pre>
  
  <p>In my head, this applies <code>abs</code> to the result of subtracting two numbers. However, this gives me the error</p>
  
  <pre><code>* Could not deduce (Num (a -&gt; a)) arising from a use of `abs'
      (maybe you haven't applied a function to enough arguments?)
    from the context: Num a
      bound by the type signature for:
                 absoluteDifference :: Num a =&gt; a -&gt; a -&gt; a
      at C:\Users\Adam\dev\daily-programmer\e311\e311.hs:3:1-42
  * In the first argument of `(.)', namely `abs'
    In the expression: abs . (-)
    In an equation for `absoluteDifference':
        absoluteDifference = abs . (-)
  </code></pre>
  
  <p>Which I don't understand. I could trivially implement the function as</p>
  
  <pre><code>absoluteDifference a b = abs $ a - b
  </code></pre>
  
  <p>but I want to know how to compose the functions.</p>