title: Haskell - defining a function with guards inside a 'where'
body: <p>I'm just starting out at teaching myself Haskell. This code is supposed to do prime factorisation:</p>
  
  <pre><code>divides :: Integer -&gt; Integer -&gt; Bool
  divides small big = (big `mod` small == 0)
  
  lowestDivisor :: Integer -&gt; Integer
  lowestDivisor n = lowestDivisorHelper 2 n
      where lowestDivisorHelper m n
          | (m `divides` n) = m  -- these should belong to lowestDivisorHelper
          | otherwise = lowestDivisorHelper (m+1) n
  
  primeFactors :: Integer -&gt; [Integer]
  primeFactors 1 = []
  primeFactors n
      | n &lt; 1 = error "Must be positive"
      | otherwise = let m = lowestDivisor n
                    in m:primeFactors (n/m)
  </code></pre>
  
  <p>I get a parse error on the commented line. I think my problem might be that <code>lowestDivisorHelper</code> has guards, but the compiler doesn't know whether the guards belong to <code>lowestDivisorHelper</code> or <code>lowestDivisor</code>. How do I get around this?</p>
  
  <p>I should add that I didn't want to define the helper function at the top level in order to hide the implementation detail. Importing the file shouldn't take the helper function with it.</p>