Revert a CAF?
simonpj at microsoft.com
Tue Dec 6 23:09:30 CET 2011
GHCi does this somehow, so it's definitely possible; Simon M will know.
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of wren ng thornton
| Sent: 06 December 2011 17:49
| To: GHC-users List
| Subject: Revert a CAF?
| So, I have an optimization/internals question. Does the GHC API have any
| hooks for being able to revert a CAF to the original expression, thus
| discarding the previously computed result?
| The reason I'm wanting this is that I have a particular CAF which is an
| infinite list. Unfolding that list takes a fair deal of work, so we want
| to share it whenever possible; however it doesn't take an overwhelming
| amount of work, so if we know we've evaluated more of the list than
| necessary (for a long while), it'd be nice to be able to revert the
| evaluation in order to save on memory overhead (e.g., by calling relax
| :: IO()).
| I could hack something together based on unsafePerformIO and top-level
| IORefs, and it's clear that this is in fact a safe thing to do, but I'm
| worried about the semantic issues inherent in unsafePerformIOed
| top-level IORefs (e.g., the fact that their scope isn't particularly
| well defined: is it per library instance? per runtime?...).
| Unfortunately, for what I'm doing, it isn't really feasible to just
| leave the IO type in there nor to pass around the infinite list so we
| can use scoping rules to decide when to free it.
| (Feel free to offer alternative suggestions to handling this situation too.)
| Live well,
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users