File: StrictIO.hs

package info (click to toggle)
haskell-blaze-builder 0.4.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 484 kB
  • sloc: haskell: 5,920; makefile: 88; ansic: 39
file content (28 lines) | stat: -rw-r--r-- 516 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE BangPatterns #-}
-- | Demonstrate the problem with IO not allowing for unlifted types.
--
--   TODO: Not yet finished.
module StrictIO where



loop :: Int -> Int -> IO ()
loop !i !c
    | i == 1    = print c
    | otherwise = do
        !i' <- subcases
        print i'
        loop i' (c+1)
  where
    subcases
      | i `mod` 2 == 0 = do
          print "even"
          return $ i `div` 2
      | otherwise      = do
          print "odd"
          return $ i + 1
    {-# INLINE subcases #-}