Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: print Vs putStrLn


Haskell provides putStr, Putstrln functions, which write given string to standard output (terminal). putStr, putStrLn are almost same, only difference is putStrLn adds a newline character.
Prelude> :t putStr
putStr :: String -> IO ()
Prelude>
Prelude> :t putStrLn
putStrLn :: String -> IO ()

print function displays value of any printable type to the standard output device. Print function do this by calling show on its input first.

Technically print is defined like below.

print x = putStrLn (show x)
*Main> :t print
print :: Show a => a -> IO ()


Observe the signature of print function, it takes an argument ‘a’ which type should be instance of type class Show and return to IO.
*Main> print 10
10
*Main>
*Main> print [1, 2, 3]
[1,2,3]
*Main>
*Main> print 10.01
10.01
*Main>



This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: print Vs putStrLn

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×