úÎH^G_ !non-portable (uses Data.Array.IO) experimental fox@ucw.cz-The lazyarray in construction is not classic  , but has the same parameters. /Creates an lazy array, using first argument as 'zero' element for this array. 9 The list of associations is left intact until needed by  or . 'zero' element bounds of the array list of associations resulting lazy array %This method creates lazy array using   for 'zero' element.  It is just a simple wrapper of : 3mlaCreate bnds assoc = laCreate Nothing bnds (map (\(i,e)->(i,Just e)) assoc)MReturns an element on the i-th position of the lazy array. If it was already R found, just return it. If it was not found yet, consume the list of associations  until it is empty or the 'nonzero' association for i is found.  If no 'nonzero' association is found, returns 'zero'. X All visited elements from the association list are processed and not visited any more. ;When not concerned about the laziness and time complexity, (laCreate zero bnds assoc) `laAt` i = zero ` fromMaybe` (find (\(i',e)->i'==i && e/ =zero) assoc)Convert lazy array to  ". Because the result is not lazy,  this function 3forces the evaluation of the whole association list before returning, S so it should be used when the lazy array is fully contructed (ie. the association  list is ended by []). %Once again - this function is really "non-lazy"), as it traverses the whole associtation 3 list, no matter which elements from the resulting   will be needed. Even if S only 1-st element is needed and even if it could already be found, the whole rest R of the association list is processed. (Small heuristic is implemented - when all  members of resulting Array are 'nonzero'5, the traversal of the association list is stopped.) This function uses Data.Array.MArray.unsafeFreeze to convert   to  . N It is used after the whole association list is processed, so it is safe, and G when using optimised GHC build, it imposes no time or space overhead. !non-portable (uses Data.Array.IO) experimental fox@ucw.cz CThis function returns an array, which i-th element is a list, that S contains all values associated with i in the list of associations, in that order.  In other words, the result of lArray bnds assoc is (lArray bnds assoc = array bnds [(i,[e|(i',e)<-assoc,i'==i] | i< -range bnds]. LThe important difference between the two sides of previous equation is that  lArray. works in linear time, ie. each member in the assoc list is accessed  exactly once, and lArray. is lazy in its second argument. It means the assoc Y list is left intact until an i-th element of the resulting array needs to be evaluated.  At that time the assoc+ list is examined until the first pair (i,e' ) is found. 1 Until such pair is found, processed elements of assoc# are stored at appropriate indexes  in the resulting array. GThe implementation uses temporary array for such processed elements of assoc list,  that were not yet ' requested' [or ' evaluated']$ in the resulting array. This array I can be freed when all lists of the resulting array are fully evaluated. RHere is an example of how to use the monolithic lazy array. Given a graph of type     []5 we construct the dfs numbering from a given vertex. * Obviously, only the first element of the lArray is needed - ,   or Data.LazyArray.Lowlevel are better choice here. dnum::Array Int [Int]->Int->Array Int (Maybe Int) (dnum g s = amap listToMaybe marks where  list = dfs' [s] 0 " marks = lArray (bounds g) list  dfs' [] _ = []  dfs'3 (s:ss) n = (s,n) : if n == head (marks!s) then dfs' ((g!s)++ss) (n+1) else dfs' ss n bounds of the array list of associations resulting array LIt is often needed to apply some function to the list of elements belonging  to the same index. Function  lArrayMap( is provided, and could be defined like  lArrayMap f = (amap f) . lArray . Obviously, lArray = lArrayMap id. Ffunction to apply to the list of elements belonging to the same index bounds of the array list of associations resulting array This is equivalent to #lArrayMaybe = lArrayMap listToMaybe but a bit faster. bounds of the array list of associations resulting array This is equivalent to lArrayFirst zero = lArrayMap (\x->case x of []->zero; e:_->e)  but a bit faster. 'zero' element, bounds of the array list of associations resulting array      lazyarray-0.1.2Data.LazyArray.LowlevelData.LazyArrayLArraylaCreate mlaCreatelaAtlaFreezelArray lArrayMap lArrayMaybe lArrayFirstbaseGHC.ArrArray Data.MaybeNothing GHC.IOArrayIOArrayLAFtmpLAtmpghc-prim GHC.TypesInt lArrayFirst'