<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">I change as you said : <br>
      <br>
      loop :: Int -> IO ()<br>
      loop n = do<br>
          if n <= 100 <br>
          then do<br>
              let x n = n * n;<br>
              putStrLn (show n );<br>
              putChar ' ';<br>
              putStrLn (show x) ;<br>
              loop (n + 1);<br>
          else<br>
             return () ;<br>
      <br>
      main :: IO ()<br>
      main = loop 1<br>
      <br>
      but now I see these errors : <br>
      <br>
      <ul id="ide-interaction-messages-list">
        <li class="ide-errors-list">
          <div class="ide-error">
            <div class="ide-error-span">Main.hs@8:19-8:23</div>
            <div class="ide-error-msg">No instance for (Show (a0 ->
              a0)) arising from a use of `show'
              Possible fix: add an instance declaration for (Show (a0
              -> a0))
              In the first argument of `putStrLn', namely `(show x)'
              In a stmt of a 'do' block: putStrLn (show x)
              In the expression: do { let x n = n * n; putStrLn (show
              n); putChar ' '; putStrLn (show x); loop (n + 1) }</div>
          </div>
        </li>
      </ul>
      <p>Roelof<br>
      </p>
      <br>
      <br>
      <br>
      Roelof Wobben schreef op 10-5-2014 17:22:<br>
    </div>
    <blockquote cite="mid:536E4426.9090303@home.nl" type="cite">Mateusz
      Lenik schreef op 10-5-2014 17:01:
      <br>
      <blockquote type="cite">Hi,
        <br>
        <br>
        There are several issues with the code:
        <br>
        <br>
        - type annotation states that the function returns 'IO ()',
        while on the else
        <br>
           branch 'IO Int' is returned. To fix it you should either
        change the returned
        <br>
           type to 'IO Int' or replace 'return n' with 'return ()';
        <br>
        - in do notation you have to use let syntax, so 'x n = n * n'
        should be
        <br>
           'let x n = n * n';
        <br>
        - this brings us to another issue in line 'putStrLn (show x n)',
        which is
        <br>
           equivalent to 'putStrLn ((show x) n)'. You should put
        parentheses explicitly
        <br>
           to fix it, or change x definition to 'let x = n * n', so that
        you can just
        <br>
           write 'putStrLn (show x)'.
        <br>
        <br>
        Cheers!
        <br>
        Mateusz
        <br>
        <br>
        <br>
      </blockquote>
      <br>
      Is it valid Haskell if I change the putStrln to putStrln ( show n
      * n) so I do not have to use the let command.
      <br>
      Another question if I change return n with return () does the loop
      ever end.  My feeling says not because the value of n is never
      updated for the loop.
      <br>
      <br>
      Roelof
      <br>
      <br>
      _______________________________________________
      <br>
      Haskell-Cafe mailing list
      <br>
      <a class="moz-txt-link-abbreviated" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>
      <br>
      <a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a>
      <br>
      <br>
    </blockquote>
    <br>
  </body>
</html>