readFile
is lazy, i.e. it doesn't actually access the data in the file until you evaluate the variable bound to it: in your case, read a
. At which time the thread delay has already passed, and you evaluate the file in the same state as b
!
Do it this way:
forever $ do
a <- fmap read $ readFile f
a `seq` threadDelay (10^6)
b <- fmap read $ readFile f
print $ b - a