how does a CAF become unreachable?

Simon Peyton Jones simonpj at
Tue Oct 12 22:10:07 UTC 2021

|  Can anyone show an example?


	xs = [1..1000] :: [Int]
	ys = [2..2000] :: [Float]

	main = do { print xs; print ys }

After printing xs, the CAF for xs is unreachable and can be GC'd.  No point in keeping it around.   Indeed this applies from the moment (print xs) begins work.  But it was
	main = do { print xs; print xs }
then the CAF for xs remains reachable until the second (print xs) starts.


PS: I am leaving Microsoft at the end of November 2021, at which point simonpj at will cease to work.  Use simon.peytonjones at instead.  (For now, it just forwards to simonpj at

|  -----Original Message-----
|  From: ghc-devs <ghc-devs-bounces at> On Behalf Of Norman
|  Ramsey
|  Sent: 12 October 2021 21:55
|  To: ghc-devs at
|  Subject: how does a CAF become unreachable?
|  I spent the afternoon spelunking through some code and the Commentary,
|  and I'm wondering how a CAF becomes unreachable.  I gather it might
|  have to do with GHC floating a static expression out of a context
|  until it becomes a CAF, but I'm still not seeing how a CAF could at
|  one point be reachable, then dynamically become unreachable.
|  Can anyone show an example?
|  Norman
|  _______________________________________________
|  ghc-devs mailing list
|  ghc-devs at
|  devs&
|  08d98dc2c6ca%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637696690459
|  913210%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJ
|  BTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=8eSDcyPcNe4gSTnKJc8OQcqQI
|  %2B%2FDf9lSp3OksAV0H%2BU%3D&reserved=0

More information about the ghc-devs mailing list