strange bug

Andreas Marth Andreas.Marth@gmx.de
Sat, 3 Mar 2001 14:43:05 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_000C_01C0A3F0.423D0E30
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_000D_01C0A3F0.423D0E30"


------=_NextPart_001_000D_01C0A3F0.423D0E30
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi again!

I cut the example a bit further down. Read the comments at the end of =
the file.
-------------------------------------------------------------------------=
--------------------------------------
>import Array
>
>data CM a =3D ZM | M (Array (Int,Int) a)  deriving (Show,Eq)
>
>data RD =3D    NB !(Double,Int)
>
>main  =3D do let arr =3D foo (NB (1.0,1))
>  putStr ("arr=3D=3DarrS "++show (arr=3D=3DarrS)++"\n")
>  putStr ("arrS=3D=3Darr "++show (arrS=3D=3Darr)++"\n")
>  putStr ("bnds arr arrS "++show ((bounds arr)=3D=3D(bounds =
arrS))++"\n")
>  putStr ("bnds +id arr arrS "++show (((bounds.id) arr)=3D=3D((bounds) =
arrS))++"\n")
>  putStr ("id +bnds arr arrS "++show (((id.bounds) arr)=3D=3D((bounds) =
arrS))++"\n")
>
>foo :: RD -> Array (Int,Int) (CM Double)
>foo rd =3D case rd of
>    NB (f,p) -> h where h=3DhCMt [(p,listArray ((1,1),(1,1)) [f])]
>   where
>   --h0CMt :: Array (Int, Int) (CM Double)
>   h0CMt =3D accumArray (\a _-> a) ZM ((1,1),(1,2)) []
>   hCMt po_arL =3D h0CMt // (map (\(po,ar) -> ((1,po),M ar)) po_arL)
>
>arrS :: Array (Int,Int) (CM Double)
>arrS =3D listArray ((1,1),(1,2)) [M (listArray ((1,1),(1,1)) [1.0]),ZM]
>-- This is the array that foo (NB (1.0,1)) shows in Hugs.
>-- But (foo (NB (1.0,1)))=3D=3DarrS is False.
>-- All in main is only to show the strange behaviour.
>-- If I write NB (f,p) -> hCMt [(p,listArray ((1,1),(1,1)) [f])] =
instead of line 16
>-- the bug disappears. That is also the reason why I have to keep the =
data declaration RD.
>-- If I put the type signature of line 18 in scope the bug also =
disappears.
>-- If I write=20
>-- hCMt po_arL =3D (accumArray (\a _-> a) ZM ((1,1),(1,2)) []) // (map =
(\(po,ar) -> ((1,po),M ar)) po_arL)
>-- instead of line 19 and 20 it also vanishes.=20
>-- So I thing now it is the shortest example that I can find. (Apart =
from deleting main.)


------=_NextPart_001_000D_01C0A3F0.423D0E30
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.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi again!</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I cut the example a bit further down. =
Read the=20
comments at the end of the file.</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;import Array</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;data CM a =3D ZM | M (Array =
(Int,Int) a)=20
&nbsp;deriving (Show,Eq)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;data RD =3D&nbsp;&nbsp;&nbsp; NB=20
!(Double,Int)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;main&nbsp; =3D do&nbsp;let arr =3D =
foo (NB=20
(1.0,1))<BR>&gt;&nbsp;&nbsp;putStr ("arr=3D=3DarrS "++show=20
(arr=3D=3DarrS)++"\n")<BR>&gt;&nbsp;&nbsp;putStr ("arrS=3D=3Darr "++show =

(arrS=3D=3Darr)++"\n")<BR>&gt;&nbsp;&nbsp;putStr ("bnds arr arrS "++show =
((bounds=20
arr)=3D=3D(bounds arrS))++"\n")<BR>&gt;&nbsp;&nbsp;putStr ("bnds +id arr =
arrS=20
"++show (((bounds.id) arr)=3D=3D((bounds) =
arrS))++"\n")<BR>&gt;&nbsp;&nbsp;putStr=20
("id +bnds arr arrS "++show (((id.bounds) arr)=3D=3D((bounds)=20
arrS))++"\n")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;foo :: RD -&gt; Array (Int,Int) (CM =

Double)<BR>&gt;foo rd =3D case rd of<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;NB=20
(f,p)&nbsp;-&gt; h where h=3DhCMt [(p,listArray ((1,1),(1,1))=20
[f])]<BR>&gt;&nbsp;&nbsp;&nbsp;where<BR>&gt;&nbsp;&nbsp;&nbsp;--h0CMt :: =
Array=20
(Int, Int) (CM Double)<BR>&gt;&nbsp;&nbsp;&nbsp;h0CMt&nbsp;=3D =
accumArray (\a=20
_-&gt; a) ZM ((1,1),(1,2)) []<BR>&gt;&nbsp;&nbsp;&nbsp;hCMt =
po_arL&nbsp;=3D h0CMt=20
// (map (\(po,ar) -&gt; ((1,po),M ar)) po_arL)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;arrS :: Array (Int,Int) (CM =
Double)<BR>&gt;arrS=20
=3D listArray ((1,1),(1,2)) [M (listArray ((1,1),(1,1)) =
[1.0]),ZM]<BR>&gt;-- This=20
is the array that foo (NB (1.0,1)) shows in Hugs.<BR>&gt;-- But (foo (NB =

(1.0,1)))=3D=3DarrS is False.<BR>&gt;-- All in main is only to show the =
strange=20
behaviour.<BR>&gt;-- If I write NB (f,p)&nbsp;-&gt; hCMt [(p,listArray=20
((1,1),(1,1)) [f])] instead of line 16<BR>&gt;-- the bug disappears. =
That is=20
also the reason why I have to keep the data declaration RD.<BR>&gt;-- If =
I put=20
the type signature of line 18 in scope the bug also =
disappears.<BR>&gt;-- If I=20
write <BR>&gt;-- hCMt po_arL&nbsp;=3D (accumArray (\a _-&gt; a) ZM =
((1,1),(1,2))=20
[]) // (map (\(po,ar) -&gt; ((1,po),M ar)) po_arL)<BR>&gt;-- instead of =
line 19=20
and 20 it also vanishes. <BR>&gt;-- So I thing now it is the shortest =
example=20
that I can find. (Apart from deleting main.)</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_001_000D_01C0A3F0.423D0E30--

------=_NextPart_000_000C_01C0A3F0.423D0E30
Content-Type: application/octet-stream;
	name="bug1.hs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="bug1.hs"

import Array

data CM a =3D ZM | M (Array (Int,Int) a) 	deriving (Show,Eq)

data RD =3D    NB !(Double,Int)

main  =3D do	let arr =3D foo (NB (1.0,1))
		putStr ("arr=3D=3DarrS "++show (arr=3D=3DarrS)++"\n")
		putStr ("arrS=3D=3Darr "++show (arrS=3D=3Darr)++"\n")
		putStr ("bnds arr arrS "++show ((bounds arr)=3D=3D(bounds =
arrS))++"\n")
		putStr ("bnds +id arr arrS "++show (((bounds.id) arr)=3D=3D((bounds) =
arrS))++"\n")
		putStr ("id +bnds arr arrS "++show (((id.bounds) arr)=3D=3D((bounds) =
arrS))++"\n")

foo :: RD -> Array (Int,Int) (CM Double)
foo rd =3D case rd of
 			NB (f,p)	-> h where h=3DhCMt [(p,listArray ((1,1),(1,1)) [f])]
			where
			--h0CMt :: Array (Int, Int) (CM Double)
			h0CMt	=3D accumArray (\a _-> a) ZM ((1,1),(1,2)) []
			hCMt po_arL	=3D h0CMt // (map (\(po,ar) -> ((1,po),M ar)) po_arL)

arrS :: Array (Int,Int) (CM Double)
arrS =3D listArray ((1,1),(1,2)) [M (listArray ((1,1),(1,1)) [1.0]),ZM]
-- This is the array that foo (NB (1.0,1)) shows in Hugs.
-- But (foo (NB (1.0,1)))=3D=3DarrS is False.
-- All in main is only to show the strange behaviour.
-- If I write NB (f,p)	-> hCMt [(p,listArray ((1,1),(1,1)) [f])] instead =
of line 16
-- the bug disappears. That is also the reason why I have to keep the =
data declaration RD.
-- If I put the type signature of line 18 in scope the bug also =
disappears.
-- If I write=20
-- hCMt po_arL	=3D (accumArray (\a _-> a) ZM ((1,1),(1,2)) []) // (map =
(\(po,ar) -> ((1,po),M ar)) po_arL)
-- instead of line 19 and 20 it also vanishes.=20
-- So I thing now it is the shortest example that I can find. (Apart =
from deleting main.)
------=_NextPart_000_000C_01C0A3F0.423D0E30--