
Hello, Can somebody help me I want to work with putStrLn main n = putStrLn "*" for example How must I define the code that:
main 5 *****
Thanks for any help -- View this message in context: http://www.nabble.com/putStrLn-t1799896.html#a4905456 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

main n = putStrLn (replicate n '*')
main n = putStrLn (take n (repeat '*'))
main n = sequence (take n (repeat (putStr "*")))
(but that doesn't have a final new line. The more complicated:
main n = sequence (take (n - 1) (repeat (putStr "*"))) >> putStrLn "*"
should solve that problem.)
/g
On 6/16/06, Jenny678
Hello,
Can somebody help me
I want to work with putStrLn main n = putStrLn "*"
for example How must I define the code that:
main 5 *****
Thanks for any help -- View this message in context: http://www.nabble.com/putStrLn-t1799896.html#a4905456 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- We have lingered in the chambers of the sea By sea-girls wreathed with seaweed red and brown Till human voices wake us, and we drown.

you already know how to write "*" one ... so you just have to know how
to do it the neded amount :
two ways : 1/ you repeat the function
2/ you reapet the data one which the function is applied.
this is like 2/
2006/6/16, J. Garrett Morris
main n = putStrLn (replicate n '*')
main n = putStrLn (take n (repeat '*'))
this is like 1/
main n = sequence (take n (repeat (putStr "*")))
in order to remove the interleaved '\n', just apply the trick (n-1) times then one more for '\n'.
(but that doesn't have a final new line. The more complicated:
main n = sequence (take (n - 1) (repeat (putStr "*"))) >> putStrLn "*"
should solve that problem.)
mt
participants (3)
-
J. Garrett Morris
-
Jenny678
-
minh thu