putStr vs. putStrLn

Andre W B Furtado aw@free.elogica.com.br
Mon, 19 Feb 2001 15:19:33 -0300


This is a multi-part message in MIME format.

------=_NextPart_000_0021_01C09A87.5D245AE0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0022_01C09A87.5D245AE0"


------=_NextPart_001_0022_01C09A87.5D245AE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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.

import IO
import IOExts

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)

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?

Thanks,
Andre Furtado

------=_NextPart_001_0022_01C09A87.5D245AE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello there. I used the code below to =
read=20
and&nbsp;print the bitmap file attached (bitmap.bmp), which contains the =

character ASCII 26&nbsp;(or 1A-hexa). This special character is used by =
MSDOS as=20
an end of file marker.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import IO<BR>import IOExts</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>main :: IO ()<BR>main =3D =
do<BR>&nbsp;bmFile &lt;-=20
openFileEx "bitmap.bmp" (BinaryMode ReadMode)<BR>&nbsp;charloop bmFile=20
0<BR>&nbsp;<BR>charloop :: Handle -&gt; Integer -&gt; IO ()<BR>charloop =
bmFile=20
70 =3D hClose bmFile<BR>charloop bmFile n =3D =
do<BR>&nbsp;&nbsp;&nbsp;hSeek bmFile=20
AbsoluteSeek n<BR>&nbsp;&nbsp;&nbsp;a &lt;- hGetChar=20
bmFile<BR>&nbsp;&nbsp;&nbsp;putStrLn [a]<BR>&nbsp;&nbsp;&nbsp;charloop =
bmFile=20
(n+1)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This program did not stuck after =
reading the=20
special character, but if you change putStrLn by putStr you will notice =
that a=20
strange thing happens: after reading the special character, the program =
won't=20
show any more characters. Why does&nbsp;it happen?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Andre =
Furtado</FONT></DIV></BODY></HTML>

------=_NextPart_001_0022_01C09A87.5D245AE0--

------=_NextPart_000_0021_01C09A87.5D245AE0
Content-Type: image/bmp;
	name="bitmap.bmp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="bitmap.bmp"

Qk1GAAAAAAAAADYAAAAoAAAAAgAAAAIAAAABABgAAAAAABAAAADEDgAAxA4AAAAAAAAAAAAAHFB3
GkxxAAAdVH4cUHcAAA==

------=_NextPart_000_0021_01C09A87.5D245AE0--