[Haskell-cafe] loop problem

Roelof Wobben r.wobben at home.nl
Sat May 10 15:22:14 UTC 2014

Mateusz Lenik schreef op 10-5-2014 17:01:
> Hi,
> There are several issues with the code:
> - type annotation states that the function returns 'IO ()', while on the else
>    branch 'IO Int' is returned. To fix it you should either change the returned
>    type to 'IO Int' or replace 'return n' with 'return ()';
> - in do notation you have to use let syntax, so 'x n = n * n' should be
>    'let x n = n * n';
> - this brings us to another issue in line 'putStrLn (show x n)', which is
>    equivalent to 'putStrLn ((show x) n)'. You should put parentheses explicitly
>    to fix it, or change x definition to 'let x = n * n', so that you can just
>    write 'putStrLn (show x)'.
> Cheers!
> Mateusz

Is it valid Haskell if I change the putStrln to putStrln ( show n * n) 
so I do not have to use the let command.
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.


More information about the Haskell-Cafe mailing list