1{-# LANGUAGE BangPatterns #-}
2-- | Demonstrate the problem with IO not allowing for unlifted types.
3--
4--   TODO: Not yet finished.
5module StrictIO where
6
7
8
9loop :: Int -> Int -> IO ()
10loop !i !c
11    | i == 1    = print c
12    | otherwise = do
13        !i' <- subcases
14        print i'
15        loop i' (c+1)
16  where
17    subcases
18      | i `mod` 2 == 0 = do
19          print "even"
20          return $ i `div` 2
21      | otherwise      = do
22          print "odd"
23          return $ i + 1
24    {-# INLINE subcases #-}
25
26
27
28
29