title: How to properly define an Haskell function isPrime?
body: <p>I'm trying to create a basic function to test primality of an integer in Haskell.  I have code which will work in an ad hoc sense, but continue to get an error message when I try to pass it to a function. Note that I'm writing the definitions directly in GHCi, using <code>:{</code> and <code>:}</code>.</p>
  
  <p>The idea is to create a list of N modulo {all integers up to a rounded sqrt (N)}, and then test the resulting list for a zero other than the initial index.  The following four functions all work:</p>
  
  <pre><code>rndRoot :: (Floating a, Integral c, RealFrac a) =&gt; a -&gt; c
  rndRoot = round . sqrt
  
  oneToRndRoot :: (Floating a, Integral t, RealFrac a) =&gt; a -&gt; [t]
  oneToRndRoot x = [1..rndRoot(x)]
  
  modulo x y
    | n &lt; 0 = x
    | otherwise = modulo n y
    where n = x - y
  
  mapMod x = map (modulo x)
  </code></pre>
  
  <p>This also works:</p>
  
  <pre><code>mapMod 49 (oneToRndRoot 49)
  </code></pre>
  
  <p>However, while the repl accepts this definition without complaint...</p>
  
  <pre><code>mapModToRndRoot x = mapMod x $ oneToRndRoot x
  </code></pre>
  
  <p>...  it spits out the following error message when I try to use it:</p>
  
  <pre><code>Prelude&gt; mapModToRndRoot 39
  
  &lt;interactive&gt;:475:1:
      No instance for (Floating a0) arising from a use of ‘it’
      The type variable ‘a0’ is ambiguous
      Note: there are several potential instances:
        instance Floating Double -- Defined in ‘GHC.Float’
        instance Floating Float -- Defined in ‘GHC.Float’
      In the first argument of ‘print’, namely ‘it’
      In a stmt of an interactive GHCi command: print it
  </code></pre>
  
  <p>The ad hoc solution which seems to work fine is just to use two arguments rather than repeat the same one</p>
  
  <pre><code>mapModToRndRoot2 x y = map (modulo x) (oneToRndRoot y)
  </code></pre>
  
  
  
  <pre><code>Prelude&gt; mapModToRndRoot2 33 33
  [0,1,0,1,3,3]
  </code></pre>