putStr vs. putStrLn

Reuben Thomas v-reubth@microsoft.com
Thu, 22 Feb 2001 05:53:06 -0800


I just tried this example with putStrLn and putStr, and both worked
fine. I am using the latest 4.08.2   GHC under Windows 2000.

-----Original Message-----
From: Andre W B Furtado [mailto:aw@free.elogica.com.br]
Sent: Monday, February 19, 2001 6:20 PM
To: Haskell@haskell.org
Cc: alms@cin.ufpe.br; jeaf@cin.ufpe.br
Subject: putStr vs. putStrLn


Hello there. I used the code below to read and print the bitmap file
attached (bitmap.bmp), which contains the character ASCII 26 (or
1A-hexa). This special character is used by MSDOS as an end of file
marker.
=20
import IO
import IOExts
=20
main :: IO ()
main =3D do
 bmFile <- openFileEx "bitmap.bmp" (BinaryMode ReadMode)
 charloop bmFile 0
=20
charloop :: Handle -> Integer -> IO ()
charloop bmFile 70 =3D hClose bmFile
charloop bmFile n =3D do
   hSeek bmFile AbsoluteSeek n
   a <- hGetChar bmFile
   putStrLn [a]
   charloop bmFile (n+1)
=20
This program did not stuck after reading the special character, but if
you change putStrLn by putStr you will notice that a strange thing
happens: after reading the special character, the program won't show any
more characters. Why does it happen?
=20