Saturday 30 April 2016

Haskell: Print data to console


putStrLn method is used to print data to console. putStr is also used to send data to console, only difference is putStrLn always prints information in newline, where as putStr prints on same line.

Syntax
putStrLn "Some data"
putStrLn ("Some data")
putStr "Some data"
putStr ("Some data")

print_data.hs
print_info = 
    do
        putStrLn ("Hello World")
        putStrLn "Hello World"

        putStr "Hello World"
        putStr ("Hello World")

*Main> :load print_data.hs
[1 of 1] Compiling Main             ( print_data.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> print_info
Hello World
Hello World
Hello WorldHello World*Main>


 ‘do’ statement is used to combine multiple actions (statements) together.

Previous                                                 Next                                                 Home

No comments:

Post a Comment