Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell] Data.Hashtable operations in IO?

0 views
Skip to first unread message

ROBERT DOUGLAS HOELZ

unread,
Feb 20, 2007, 11:28:50 AM2/20/07
to has...@haskell.org
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
_______________________________________________
Haskell mailing list
Has...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Chris Kuklewicz

unread,
Feb 20, 2007, 11:46:12 AM2/20/07
to ROBERT DOUGLAS HOELZ
ROBERT DOUGLAS HOELZ 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
>
> 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.

0 new messages