putStrLn

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

putStrLn

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
Reply | Threaded
Open this post in threaded view
|

Re: putStrLn

J. Garrett Morris
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 <[hidden email]> wrote:

>
> 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
> [hidden email]
> 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.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: putStrLn

Vo Minh Thu
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 <[hidden email]>:
> 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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe