Sorry if this has been reported before. I shouldn't be able to crash ghc or hugs without using any "unsafe" features, right? Well, here 'tis:
module CrashArray where
import Array import Ix
newtype CrashIx = CrashIx Int deriving (Ord, Eq, Show)
instance Enum CrashIx where toEnum x = (CrashIx x) fromEnum (CrashIx x) = x
instance Ix CrashIx where inRange (_,_) _ = True index (_,_) (CrashIx x) = x range (x,y) = [x..y]
myArray = listArray (CrashIx 0, CrashIx 0) [0] crash = myArray ! (CrashIx maxBound)
In ghci-5.00, I get a segfault and hugs-feb-2000 says: INTERNAL ERROR: Error in graph Now, admittedly my Ix instance is broken, but I don't think I should be able to segfault the interpreter. Unfortunately, I think the only way to fix this without changing the Library Report would be to add another layer of range checking to the array implementation. Bleh. Note also that the (inefficient) implementation in the report wouldn't crash, but would get the "wrong" error: "Undefined array element" instead of "Index out of range". I think we might describe this as a bug in the Library Report, rather than in any particular Haskell implementation. Enjoy! Matt Harden
Matt Harden wrote:
blah, blah, blah, bug in the Library Report, blah, blah...
OK, so I failed to read the Library Report. It clearly states:
An implementation is entitled to assume the following laws about these operations:
range (l,u) !! index (l,u) i == i -- when i is in range inRange (l,u) i == i `elem` range (l,u)
So my "bug" is only in my mind. Sorry for bothering everyone. Regards, Matt
On 02-May-2001, Matt Harden
Matt Harden wrote:
blah, blah, blah, bug in the Library Report, blah, blah...
OK, so I failed to read the Library Report. It clearly states:
An implementation is entitled to assume the following laws about these operations:
range (l,u) !! index (l,u) i == i -- when i is in range inRange (l,u) i == i `elem` range (l,u)
So my "bug" is only in my mind. Sorry for bothering everyone.
I don't think it's quite as straight-forward as that.
Hugs and ghc may conform to the Library Report, but the
behaviour is still undesirable, and IMHO should be fixed.
--
Fergus Henderson
participants (2)
-
Fergus Henderson -
Matt Harden