I am confused. I try to use print
, but I know people apply putStrLn
. What are the real differences between them?
print $ function
putStrLn $ function
I am confused. I try to use print
, but I know people apply putStrLn
. What are the real differences between them?
print $ function
putStrLn $ function
The function
putStrLn
takes aString
and displays it to the screen, followed by a newline character (put a String followed by a new Line).Because it only works with
String
s, a common idiom is to take any object, convert it to aString
, and then applyputStrLn
to display it. The generic way to convert an object to aString
is with theshow
function, so your code would end up with a lot ofOnce you notice that, it's not a very big stretch to define a function that converts to a
String
and displays the string in one stepwhich is exactly what the
print
function is.