[Haskell] Data.Hashtable operations in IO?

Kirsten Chevalier catamorphism at gmail.com
Tue Feb 20 12:02:25 EST 2007

[redirecting to a more appropriate mailing list]

On 2/20/07, ROBERT DOUGLAS HOELZ <hoelz at wisc.edu> wrote:
> 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

If you read the source for Data.HashTable, you'll notice that the
HashTable type is defined in terms of mutable arrays, which must be in
the IO monad since side effects are involved. This is purely for
performance reasons. If you want an analogous type whose operations
are pure, look at Data.Map:


Kirsten Chevalier* chevalier at alum.wellesley.edu *Often in error, never in doubt
"Nuclear war can ruin your whole compile." -- Karl Lehenbauer

More information about the Glasgow-haskell-users mailing list