loops 0.2.0.1 → 0.2.0.2
raw patch · 4 files changed
+16/−3 lines, 4 filesdep ~base
Dependency ranges changed: base
Files
- loops.cabal +1/−1
- src/Control/Monad/Loop/Internal.hs +2/−2
- test/Test.hs +1/−0
- test/Test/Sum.hs +12/−0
loops.cabal view
@@ -1,5 +1,5 @@ name: loops-version: 0.2.0.1+version: 0.2.0.2 synopsis: Fast imperative-style loops description: @loops@ is a library for fast, imperative-style loops with a clean syntax.
src/Control/Monad/Loop/Internal.hs view
@@ -54,14 +54,14 @@ pure a = LoopT $ \yield -> yield a {-# INLINE (<*>) #-} fs <*> as = LoopT $ \yield next ->- runLoopT fs (\f next' _ -> runLoopT (fmap f as) yield next' next) next+ runLoopT fs (\f -> runLoopT (fmap f as) yield) next instance Monad (LoopT m) where {-# INLINE return #-} return = pure {-# INLINE (>>=) #-} as >>= f = LoopT $ \yield next ->- runLoopT as (\a next' _ -> runLoopT (f a) yield next' next) next+ runLoopT as (\a -> runLoopT (f a) yield) next instance MonadTrans LoopT where {-# INLINE lift #-}
test/Test.hs view
@@ -12,5 +12,6 @@ , QC.testProperty "foldr" prop_sum_foldr_LoopT , QC.testProperty "foldl (Unroll)" prop_sum_foldl_LoopT_Unroll , QC.testProperty "foldr (Unroll)" prop_sum_foldr_LoopT_Unroll+ , QC.testProperty "break order" prop_break_order ] ]
test/Test/Sum.hs view
@@ -29,3 +29,15 @@ where unroll :: Unroll.Unroll 8 unroll = Unroll.Unroll++prop_break_order :: [Int] -> Property+prop_break_order xs =+ foldl' (+) 0 before === foldl' (+) 0 after+ where+ before = LoopT.loop $ do+ x <- LoopT.forEach xs+ if x < 10 then LoopT.continue 10 else LoopT.break_+ after = LoopT.loop $ do+ x <- LoopT.forEach xs+ return ()+ if x < 10 then LoopT.continue 10 else LoopT.break_