title: Haskell ReplicateM IO
body: <p>I'm trying to create a function which allows the user to input a list of strings. The function takes the length and allows the user to input length-1 more lines. Then each line is checked to ensure it is the same length as the original line. However, I'm having a few problems and that I can't find a solution to. </p>
  
  <p>The problems are that I can input more than count-1 lines and the length isn't being calculated as I expected.. for example if I input ["12","13"] and then ["121","13"] the error is given, although they are the same length!</p>
  
  <pre><code>read :: IO [Line]
  read = do
    line &lt;- getLine
    let count = length line
    lines &lt;- replicateM (count-1) $ do
      line &lt;- getLine
      if length line /= count
      then fail "too long or too short"
      else return line
    return $ line : lines
  </code></pre>
  
  <p>Line is of type String.</p>
  
  <p>readLn gives a parse error.</p>