[Haskell-cafe] loop problem

Taylor Hedberg t at tmh.cc
Sat May 10 15:45:11 UTC 2014


On Sat, May 10, 2014 at 8:22 AM, Roelof Wobben <r.wobben at home.nl> wrote:
>
> Is it valid Haskell if I change the putStrln to putStrln ( show n * n) so
> I do not have to use the let command.
>

You would need to write putStrLn (show (n * n)) in order for it to parse
the way you intend. Function application is left-associative. You could
also use print instead of putStrLn, which is shorthand for this.

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.


Yes, the loop would terminate. The return n in your code is not updating n.
The next iteration of the loop receives a new value of n as its argument
due to your passing it in with loop (n + 1).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140510/7128288e/attachment.html>


More information about the Haskell-Cafe mailing list