|Portability||Non-portable (rank-2 types)|
|Maintainer||Dan Doel <email@example.com>|
The purpose of this module is to supply various combinators for commonly used idioms for the algorithms in this package. Examples at the time of this writing include running an algorithm keyed on some function of the elements (but only computing said function once per element), and safely applying the algorithms on mutable arrays to immutable arrays.
- apply :: UA e => (forall s. MUArr e s -> ST s ()) -> UArr e -> UArr e
- usingKeys :: (UA e, UA k, Ord k) => (forall e'. UA e' => Comparison e' -> MUArr e' s -> ST s ()) -> (e -> k) -> MUArr e s -> ST s ()
- usingIxKeys :: (UA e, UA k, Ord k) => (forall e'. UA e' => Comparison e' -> MUArr e' s -> ST s ()) -> (Int -> e -> k) -> MUArr e s -> ST s ()
Safely applies a mutable array algorithm to an immutable array.
Uses a function to compute a key for each element which the algorithm should use in lieu of the actual element. For instance:
usingKeys sortBy f arr
should produce the same results as:
sortBy (comparing f) arr
the difference being that usingKeys computes each key only once which can be more efficient for expensive key functions.