[Haskell-cafe] Space questions about intern and sets

Scott Turner p.turner at computer.org
Thu Jun 2 09:09:31 EDT 2005

On 2005 June 02 Thursday 04:38, 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.

To avoid unsafe operations and get control over the dictionaries that are 
created, I would put the desired dictionaries into a state monad.  The type 
of 'intern' becomes
    Ord a => a -> DictionaryState a
All the code that uses 'intern' would need some modification to deal more 
directly with the dictionary state. It may be more complex, but it's also 
more solid.

More information about the Haskell-Cafe mailing list