@@ -53,6 +53,17 @@ main = hspec $ do
5353 ((toList $ (((return 0 <|> return 1) <|> (return 2 <|> return 3))
5454 <|> ((return 4 <|> return 5) <|> (return 6 <|> return 7)))
5555 ) >>= return . sort) `shouldReturn` ([0..7] :: [Int])
56+ it "loopHead" $
57+ toList (loopHead (0 :: Int)) `shouldReturn` ([3, 2..0] :: [Int])
58+ it "loopHeadA" $
59+ (toList (loopHeadA (0 :: Int)) >>= return . sort)
60+ `shouldReturn` ([0..3] :: [Int])
61+ it "loopTail" $
62+ toList (loopTail (0 :: Int)) `shouldReturn` ([0..3] :: [Int])
63+ it "loopTailA" $
64+ (toList (loopTailA (0 :: Int)) >>= return . sort)
65+ `shouldReturn` ([0..3] :: [Int])
66+
5667 {-
5768 it "Alternative composition of async and sync tasks" $
5869 ((wait (threads 0 ((async (return 0) <|> return 1)))) >>= return . sort)
@@ -149,7 +160,29 @@ main = hspec $ do
149160 )
150161 ) >>= return . sort)
151162 `shouldReturn` ([0, 1] :: [Int])
163+ -}
164+ where
165+ loopHead x = do
166+ -- this print line is important for the test (causes a bind)
167+ liftIO $ putStrLn "LoopHead..."
168+ (if x < 3 then loopHead (x + 1) else empty) <> return x
169+
170+ loopHeadA x = do
171+ -- this print line is important for the test (causes a bind)
172+ liftIO $ putStrLn "LoopHeadA..."
173+ (if x < 3 then loopHeadA (x + 1) else empty) <|> return x
174+
175+ loopTailA x = do
176+ -- this print line is important for the test (causes a bind)
177+ liftIO $ putStrLn "LoopTailA..."
178+ return x <|> (if x < 3 then loopTailA (x + 1) else empty)
179+
180+ loopTail x = do
181+ -- this print line is important for the test (causes a bind)
182+ liftIO $ putStrLn "LoopTail..."
183+ return x <> (if x < 3 then loopTail (x + 1) else empty)
152184
185+{-
153186generalExample :: AsyncT IO Int
154187generalExample = do
155188 liftIO $ return ()