unsafePerformIO and NOINLINE Pragma

Jan Christiansen jac at informatik.uni-kiel.de
Tue Sep 13 09:52:18 EDT 2005


I want to analyse the laziness of a data structure. To check how many nodes 
are constructed I use a global counter.

counter :: IORef Int
counter = unsafePerformIO (newIORef 0)

This counter is increased every time the constructor is called by redefining 
the constructor OBDD as follows.

oBDD low var high =
  seq (unsafePerformIO (modifyIORef counter (+1))) (OBDD low var high)

This works fine. 
When I compile with optimisations the counter is always set to one no matter 
how many nodes are constructed. I thought this would be caused by inlining. 
Therefore I have added two NOINLINE pragmata.

{-# NOINLINE counter #-}

Although the counter doesn't work. Is there another optimisation that can 
cause harm? Is there something wrong with the pragmata?

best regards, Jan

More information about the Glasgow-haskell-users mailing list