
On 09 November 2004 11:54, Graham Klyne wrote:
I've not been following the Global variables debate too closely, it seeming to have something of a religious wars flavour, but I noticed that an example being proposed was how to achieve a "one shot" execution. Here's something I did when working on modifications to the HaXML parser:
[[ -- Memoization of withSocketsDo to prevent multiple calls. -- (cf. http://tangentsoft.net/wskfaq/articles/lame-list.html) socketsInitialized :: Bool socketsInitialized = unsafePerformIO ( withSocketsDo ( return True ) ) ]]
Does it work as I think it does? ARe there any problems I'm overlooking?
You should add {-# NOINLINE socketsInitialized #-} to be on the safe side, but in practice GHC won't inline it anyway. The pragma would be good documentation though. Cheers, Simon