problems with Array.elems in ghc-5.02
Bostjan Slivnik
bostjan.slivnik at fri.uni-lj.si
Tue Oct 23 16:01:07 EDT 2001
Hi,
I am afraid I have to report a bug in the Array module which is a part
of ghc-5.02. Consider the following program:
module Main where
import Array
import List
data Foo = Foo Int [Foo]
instance Eq Foo where (==) (Foo f1 _) (Foo f2 _) = (==) f1 f2
instance Ord Foo where compare (Foo f1 _) (Foo f2 _) = compare f1 f2
instance Ix Foo where
range (lo@(Foo _ foos),hi) = (filter ((<=)lo).filter ((>=)hi)) foos
inRange (Foo lo _,Foo hi _) (Foo f _) = inRange (lo,hi) f
index _ (Foo f _) = f
instance Show Foo where showsPrec _ (Foo f _) = shows f
lstOfFoos = [Foo f lstOfFoos|f<-[2..5]]
arrOfFoos = array (head lstOfFoos,last lstOfFoos) (zip lstOfFoos lstOfFoos)
main :: IO ()
main = do putStr (show lstOfFoos); putStr "\n"
putStr (show ((length.indices) arrOfFoos)); putStr "\n"
putStr (show ((length.elems ) arrOfFoos)); putStr "\n"
putStr (show ((indices) arrOfFoos)); putStr "\n"
putStr (show ((elems ) arrOfFoos)); putStr "\n"
It works fine when compiled with ghc-5.00.2, but when compiled with
ghc-5.02 the last `putStr' crashes with
Fail: (Array.!): undefined array element
The length of the elements, as it is printed out, equals the length of
the indices plus the lower bound of the interval, in this case 2.
Hence, if the list `[2..5]' is replaced with `[0..3]', the program
works find with both version of the compiler.
(This can be reproduced on RedHat 7.1 using Chakravarty's binary rpms.)
Cheers, Bo"stjan
More information about the Glasgow-haskell-bugs
mailing list