space invariant broken through loss of sharing

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
29
30
31
32
33
import Control.Concurrent (threadDelay)
import Control.Exception (evaluate)
import System.Environment (getArgs)
import GHC.Vis

{-# NOINLINE complicated #-}
complicated :: Int -> Int -> Int
complicated n k = n + k

headStrictify :: [a] -> [a]
headStrictify [] = []
headStrictify xs@(x:_) = x `seq` xs

f :: Int -> [Int]
f n = headStrictify [x,y,z]
  where x = complicated n 1
        {-# INLINE x #-}
        y = complicated n 2
        z = complicated n 3

main = do
  input <- fmap (read . head) getArgs
  evaluate input
  let a = f input               -- Head strict?

  visualization
  switch
  view a "a"
  threadDelay 3000000

  evaluate a
  update
  threadDelay 3000000