loop-0.2.0: Fast loops (for when GHC can't optimize forM_)

Safe HaskellSafe-Inferred



This is for trying out loop alternatives.

Names and types are subjects to change.



loop :: (Enum e, Eq e, Monad m) => e -> e -> (e -> m ()) -> m ()Source

loop start end f: Loops from start to end (inclusive), executing f on each iteration. Same as forM_ [start..end] f.

Uses succ inside, which does a bounds (overflow) check.

unsafeLoop :: (Enum e, Eq e, Monad m) => e -> e -> (e -> m ()) -> m ()Source

Like loop, but (sometimes) without bounds (overflow) check.

This circumvents the implementation of succ for the Enum type and uses toEnum . (+ 1) . fromEnum instead, so it will break on Enums that are not contiguous.

Note that some types (e.g. Word32) have bounds checks even for toEnum.