[Haskell] Data.Hashtable operations in IO?

Chris Kuklewicz haskell at list.mightyreason.com
Tue Feb 20 11:45:41 EST 2007

> I was reading the docs for Data.Hashtable, and quickly noticed that operations on a hashtable are of the IO monad.  Why is this?  I should think that the operations would look like this:
> insert :: Hashtable -> key -> val -> Hashtable
> lookup :: Hashtable -> key -> a
> etc.
> Thanks,
> Rob Hoelz

That would be the signature for immutable hashtables.  The old and new ones
would be distinct and could co-exist.  Building an immutable hashtable on top of
Data.Array or Data.Map would be fairly easy.

Data.Hashtable is a mutable hashtable.  After an insert the old Hashtable no
longer exists -- there is only the new one.  Thus operations needs to be
ordered.   Rightfully, there should be a Data.Hashtable.ST as well.

The standard Haskell libraries have yet to include one of the type class
approaches to immutable collections and have very little in the way of mutable
data structures.

The former is probable due to lack of standardization of MPTC / fundeps /
associated types.  The latter is due to both lack of sufficient interest and the
same lack of a standard for fancier type classes.

More information about the Haskell mailing list