title: Adding an element to each permutation of a nested list in Haskell
body: <p>Let's say I have a nested list </p>
  
  <pre><code>[1,2,3]
  </code></pre>
  
  <p>When I use the Data.List module to permutate this list, the result is the following:</p>
  
  <pre><code>&gt; permutations [1,2,3]
  =&gt; [[1,2,3],[2,1,3],[3,2,1],[2,3,1],[3,1,2],[1,3,2]]
  </code></pre>
  
  <p>But I want it such that, I'm concatenating a 0 at the end of each tail. Example:</p>
  
  <pre><code>=&gt; [[1,2,3,0],[2,1,3,0],[3,2,1,0],[2,3,1,0],[3,1,2,0],[1,3,2,0]]
  </code></pre>
  
  <p>I'm thinking that the only way of doing this is modifying the source code of permutations as a different function but I'm not sure how to incorporate the concatenation into it. This would be the source:</p>
  
  <pre><code>import Data.List
  
  permutations            :: [a] -&gt; [[a]]
  permutations xs0        =  xs0 : perms xs0 []
    where
      perms []     _  = []
      perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is)
        where interleave    xs     r = let (_,zs) = interleave' id xs r in zs
              interleave' _ []     r = (ts, r)
              interleave' f (y:ys) r = let (us,zs) = interleave' (f . (y:)) ys r
                                       in  (y:us, f (t:y:us) : zs)
  </code></pre>
  
  <p>If there's a better way to approach this by using the permutation function without permutating the zero, it would be much appreciated. </p>