[Haskell-beginners] glib heterogenous hash table

John Obbele john.obbele at gmail.com
Sun Sep 5 16:57:45 EDT 2010

Hi everyone !

To exercise my Haskell skills, I'm currently trying to bind
libxfconf-0 with Haskell. A small preview can be found on

[0]: https://patch-tag.com/r/obbele/xfconf/home

Since XFCE projects rely heavily on glib, I am borrowing (lots
of) code from the gtk2hs package(s). I am still having issues
with gobject casts and foreign pointer finalizers, but lets focus
on GHashTable for now.

For those who are not familiar with glib (neither I am),
GHashTable[1] are hashes with homogenous key types but values of
arbitrary types. In xfconf, keys are all cstring but values can
be any type of gpointers (gchar *, gint*, gdouble*, widget*,
struct* ?).

[1]: http://library.gnome.org/devel/glib/stable/glib-Hash-Tables.html

I've tried to wrap the glib hash table in a haskell data type
this way:

> data GHashTable k v = GHashTable GHashTablePtr

The GHashTablePtr is our Haskell foreign pointer, courtesy
of C→HS. It is bound later with a g_hash_table_destroy finalizer
in order to (automatically) manage memory .

My real problems are:
- I cannot simply map (GHashTable k v) to a (Data.Map.Map k v)

- I don't know how to constraint k and v to be C pointers (Ptr
  CChar is ok but not Char or CChar).

Does anyone have a solution or some pointers on it ?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/beginners/attachments/20100905/eab824c9/attachment.bin

More information about the Beginners mailing list