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