Skip to content
  • meooow's avatar
    9dd4cc32
    Add fold functions for arrays · 9dd4cc32
    meooow authored and Lei Zhu's avatar Lei Zhu committed
    At the moment it is quite difficult to perform some folds on some
    arrays.
    
    * In general, arrays can be folded over by folding over the range of
      indices and then indexing into the array. This is a little cumbersome,
      and also inefficient when folding right-to-left because Ix does not
      offer reversed range generation.
    * Alternately, Array has a Foldable instance which works great, but
      UArray cannot be Foldable. Folds on UArray can instead be done via
      elems. Due to list fusion, this works out well for some folds (foldr,
      foldl'), but not others (foldr').
    * For mutable arrays, there are no alternate ways to fold.
    
    This commit adds some commonly used folds for arrays and mutable arrays
    to improve this situation.
    9dd4cc32
    Add fold functions for arrays
    meooow authored and Lei Zhu's avatar Lei Zhu committed
    At the moment it is quite difficult to perform some folds on some
    arrays.
    
    * In general, arrays can be folded over by folding over the range of
      indices and then indexing into the array. This is a little cumbersome,
      and also inefficient when folding right-to-left because Ix does not
      offer reversed range generation.
    * Alternately, Array has a Foldable instance which works great, but
      UArray cannot be Foldable. Folds on UArray can instead be done via
      elems. Due to list fusion, this works out well for some folds (foldr,
      foldl'), but not others (foldr').
    * For mutable arrays, there are no alternate ways to fold.
    
    This commit adds some commonly used folds for arrays and mutable arrays
    to improve this situation.
Loading