[Haskell-cafe] Space questions about intern and sets

Udo Stenzel u.stenzel at web.de
Wed Jun 8 11:15:18 EDT 2005

Gracjan Polak wrote:
> >>iorefset :: Ord a => IORef(Map.Map a a)
> >>iorefset = unsafePerformIO $ do
> >>     newIORef $ Map.empty
> I could have as many dictionaries as there are types. The problem is I 
> get one dictionary for each object which defeats the idea.

I believe the (Ord a) constraint acts like a function argument.
Therefore iorefset is no CAF, cannot be memoized itself and you get one
dictionary per invocation.  On the other hand, that is what is to be
expected when playing games with unsafePerformIO.

You might get it working by giving iorefset a monomorphic type or by
specializing it for the type(s) you are using it at.  Don't forget the
NOINLINE pragma.  I wouldn't do it this way, though.  If you're parsing,
chances are that your code is monadic anyway.  Put a StateT over the
parser monad and everything works without black magic.  Even better, if
you're using parsec you can just put the Map in the user state.

"Mind if I smoke?"
        "I don't care if you burst into flames and die!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20050608/61df1326/attachment.bin

More information about the Haskell-Cafe mailing list