Saturday 14 May 2016

Haskell: print : print data to console

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> 




Previous                                                 Next                                                 Home

No comments:

Post a Comment