<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Thanks , it's working now like this : <br>
<br>
loop :: Int -> IO ()<br>
loop n = do<br>
if n <= 100 <br>
then do<br>
putStrLn (show n );<br>
putChar ' ';<br>
putStrLn (show (n * n )) ;<br>
loop (n + 1);<br>
else<br>
return () ;<br>
<br>
main :: IO ()<br>
main = loop 1<br>
<br>
But the outcome looks like this: <br>
<br>
1 <br>
1<br>
2 <br>
4 <br>
<br>
Can I somehow make it like this <br>
<br>
1 1<br>
2 4<br>
3 9 <br>
<br>
Roelof<br>
<br>
<br>
<br>
Taylor Hedberg schreef op 10-5-2014 17:45:<br>
</div>
<blockquote
cite="mid:CANuVROTJ-fVQSJ0LJJrkLp1nBY+==U5vZN3y644NRyt5ugRW8g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Sat, May 10, 2014 at 8:22 AM,
Roelof Wobben <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span>
wrote:
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
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>
</blockquote>
<div><br>
</div>
<div>You would need to write <font face="courier new,
monospace">putStrLn (show (n * n))</font><font
face="arial, helvetica, sans-serif"> in order for it to
parse the way you intend. Function application is
left-associative.</font> You could also use <font
face="courier new, monospace">print</font><font
face="arial, helvetica, sans-serif"> instead of </font><font
face="courier new, monospace">putStrLn</font><font
face="arial, helvetica, sans-serif">, which is shorthand
for this.</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
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.</blockquote>
<div><br>
</div>
<div>Yes, the loop would terminate. The <font face="courier
new, monospace">return n</font> in your code is not
updating <font face="courier new, monospace">n</font><font
face="arial, helvetica, sans-serif">. The next iteration
of the loop receives a new value of </font><font
face="courier new, monospace">n</font><font face="arial,
helvetica, sans-serif"> as its argument due to your
passing it in with </font><font face="courier new,
monospace">loop (n + 1)</font><font face="arial,
helvetica, sans-serif">.</font></div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>