[EMAIL PROTECTED] (Nils Ellmenreich) writes:
> it would be *very helpful* to have a better error
> message [than {_undefined_array_element}], stating at least the
> index of the undefined element and perhaps even the arrays name.
> I tried to enclose every array access with a trace call, but it
> didn't help.

The most obvious fix is to build your own Array implementation
(or maybe just your own implementation of Array.array?).
It seems like you'd get a long way with a definition like:

  [untested code]
  myArray :: (Ix a, Show a) => (a,a) -> [(a,b)] -> Array a b
  myArray bs assocs = myEmptyArray bs // assocs

  myEmptyArray :: (Ix a, Show a) => (a,a) -> Array a b
  myEmptyArray bs = listArray bs (map myEmptyElement (range bs))

  myEmptyElement (Show a) => a -> b
  myEmptyElement ix = (ix, error ("undefined array element at " ++ show ix))

> I tried a lot up to now and suspect in 
> the end the run time system might have a different evaluation order than 
> I would like.

I'm wondering if you're referring to the fact that Haskell arrays are
strict in the index list.  That is, the array is completely filled
in with values the first time you do anything with the array.
This can be a problem (and can cause huge jumps in space usage).
One solution is to use LML's lazy arrays.  I believe hbc supports these
and I've heard rumours of implementations for GHC/Hugs using lazy ST
operations.


-- 
Alastair Reid              Yale Haskell Project Hacker
[EMAIL PROTECTED]  http://WWW.CS.Yale.EDU/homes/reid-alastair/



Reply via email to