title: Why does my prime factorization function append 1 to the result?
body: <p>I am creating a function to factorize any given number in haskell. And so i have created this:</p>
  
  <pre><code>primes :: [Integer]
  primes = 2:(sieve [3,5..])
      where
          sieve (p:xs) = p : sieve [x |x &lt;- xs, x `mod` ((p+1) `div` 2 ) &gt; 0]
  
  
  factorize 2 = [2]
  factorize x
      | divisible x = w:(factorize (x `div` w))
      | otherwise   = [x]
      where
            divisible :: Integer -&gt; Bool
            divisible y = [x |x &lt;- (2:[3,5..y]), y `mod` x == 0] /= []
  
            firstfactor :: Integer -&gt; [Integer] -&gt; Integer
            firstfactor a (x:xs)
                | a `ifdiv` x = x
                | otherwise   = firstfactor a xs
            firstfactor a _ = a
  
            ifdiv x y = mod x y == 0
  
            w = firstfactor x primes
  </code></pre>
  
  <p>The function works fine, but appends 1 to the end of the list, for example <code>factorize 80</code> would give this list: <code>[2,2,2,2,5,1]</code> My question is, why does this happen?</p>