Hi John, On Sep 7, 2010, at 16:40, John Obbele wrote:
> Hi everyone ! > > Sorry for the double post between haskell-beginners and this > mailing-list but I am having trouble binding some part of Glib > and Xfconf to Haskell. > > Below is my original post: > =================================================================== > To exercise my Haskell skills, I'm currently trying to bind > libxfconf-0 with Haskell. A small preview can be found on > patch-tag[0]. > > [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 what you mean with "map". If you want to bind GHashTable then you providing an interface to a set of C functions that you can use in the IO monad to use the GHashTable. Maybe that's not that useful since Haskell provides it's own hashtables. Usually I would only bind what you need from GLib and expose the really useful functions of the library that builds on glib. > - I don't know how to constraint k and v to be of type (Ptr a) (Ptr > CChar is ok but not Char or CChar). I remebered from RWH that > type constraints on data type declarations are evil, so > should I just let things be this way ? > Usually the phantom type variables are enough. If you have a lookup function that compares elements by a comparison function, you can provide an argument for an explicit comparison function, or add (Eq a => ..) to just the lookup function and then use (==) as the equality test. Cheers, Axel > Does anyone have a solution or some pointers on it ? > =================================================================== > > Thanks for your efforst on glib/gtk2hs and > thanks for your time, > /John > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd_______________________________________________ > Gtk2hs-devel mailing list > Gtk2hs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Gtk2hs-devel mailing list Gtk2hs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel