Previous Next Home
Prelude System.IO> :t hPrint
hPrint :: Show a => Handle -> a -> IO ()
Observe the signature of hPrint, it takes a Handle, variable ‘a’, which derives Show class and write it to the file.
Observe the output, hPrint overrides the existing data in the file abc.txt.
Difference between hPrint, hPutStrLn
hPrint function displays value of any printable type to the standard output device. hPrint function do this by calling show on its input first.
Technically hPrint is defined like below.
hPrint x = hPutStrLn (show x)