Please, no tirade about banishing unsafePerformIO.

I've seen this done before I just don't remember how.  I want to use a
state monad to count things, but don't want to monadify the thing I'm
using the counter in.

basically, i want a function getVar :: () -> String which returns a new
string every time.  i tried this:

> curVarId = newSTRef (0 :: Integer)
> 
> {-# NO-INLINE newVar -} 
>
> newVar = \_ -> ('\0' : show x)
>     where y = unsafePerformIO (stToIO curVarId)
>           x = unsafePerformIO $ stToIO $
>                 do x <- readSTRef y
>                    writeSTRef y (x + 1)
>                    return x

and in ghci it works wonderfully, but when i actually compile, all i get
is "\NUL0".

what's the proper way to write this?

thanks

 - hal


_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to