title: perform a function on first elements of list
body: <p>In an attempt to write the Havel-Hakimi algorithm in Haskell, I wrote following function to subtract 1 from the first n elements of a list.</p>
  
  <pre><code>decrease_first :: Int -&gt; [Int] -&gt; [Int]
  decrease_first 0 l = l
  decrease_first n (x:xs) = (x-1):decrease_first (n-1) xs
  </code></pre>
  
  <p>This code works, but as I am trying to prepare for a Haskell-test and I was convinced this code is rather lame, I wanted to rewrite this function as follows: </p>
  
  <pre><code>decrease_first :: Int -&gt; [Int] -&gt; [Int]
  decrease_first = map (subtract1) . take
  </code></pre>
  
  <p>I'm aware of the fact this does not do exactly the same, but I was just trying to understand partially applied functions etc. better and wanted to give this function a try. This turned out not to be the greatest of ideas, because I didn't get this compiled (type-definitions) and I am left with a massive mind-you-know-what, because next code does work, even though I considered it equivalent:</p>
  
  <pre><code>decrease_first n = map (subtract1) . take n 
  </code></pre>
  
  <p>and this code fails again:</p>
  
  <pre><code>decrease_first n l = map (subtract1) . take n l
  </code></pre>
  
  <p>Moreover I tried looking for some nice way to apply a function to the first elements of a list, but I couldn't find anything. The first way is probably the most efficient way to do it, but I was wondering whether there was some way to apply any function on the first elements of a list. My idea eventually was to do something like: </p>
  
  <pre><code>decrease_first n l = map (subtract 1) (take n l) ++ drop n l
  </code></pre>
  
  <p>It works like this, but it doesn't look as nice as I had it in mind. So if anyone could help me resolving my type-issue, I would be very grateful.</p>
  
  <p>Thanks in advance</p>